Skip to content

Quiz 4: Part 2

Objective

Use what you’ve learned so far in this module about building and managing containers.

Prerequisites

  • Access to your instance with Docker installed.Follow the steps in Lab Environment to access your machine.
  • Basic familiarity with Linux command line.
  • Sudo access

Duration: 60 minutes

Tasks

Task 1: Initial Setup

  • Create a new directory name nginx-lab2 and inside the folder create a Dockerfile

Task 2: Edit Dockerfile and add the following configuration

  2.1. Instruct Docker to create an image based on another image

FROM ubuntu

  2.2. Install Nginx package from the official page using apt

RUN apt-get -y update && apt-get -y install nginx

  2.3. Create your own default configuration file

server { listen 80 default_server;
    listen [::]:80 default_server;

    root /usr/share/nginx/html;
    index index.html index.htm;

    server_name _;
    location / {
        try_files $uri $uri/ =404;
    }
}
  2.4. Add entry in the Dockerfile for copying our configuration file
COPY default /etc/nginx/sites-available/default
  2.5. Expose the port on which we’ll access our server

EXPOSE 8090/tcp

  2.6. Run Nginx whenever Docker images launches

CMD ["/usr/sbin/nginx", "-g", "daemon off;"]

Task 3: Build the image

  • Using the Dockerfile on task 2, build the image and use image tag nginx-web.

Task 4: Once the image is built successfully, take it for a test run.

  • Run the image nginx-web in detached mode and name it as nginx-acads2. Use port 8090 and expose it on both container and server.

Task 5: Access the application using your browser

  • Fire up your favorite browser and check your newly-built server using port 8090.