Bird
Raised Fist0
Nginxdevops~10 mins

Official Nginx Docker image - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the Docker command to pull the official Nginx image from Docker Hub.

Nginx
docker [1] nginx
Drag options to blanks, or click blank then click option'
Arun
Bpull
Cpush
Dbuild
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' instead of 'pull' will try to start a container but fail if image is missing.
Using 'push' tries to upload an image, not download.
2fill in blank
medium

Complete the Docker command to start a container named 'webserver' from the official Nginx image, mapping port 8080 on the host to port 80 in the container.

Nginx
docker run -d --name webserver -p [1]:80 nginx
Drag options to blanks, or click blank then click option'
A8080
B80
C443
D8000
Attempts:
3 left
💡 Hint
Common Mistakes
Using 80:80 maps the same port, not 8080.
Using 443 is for HTTPS, not requested here.
3fill in blank
hard

Fix the error in the Dockerfile line to use the official Nginx image as base.

Nginx
FROM [1]
Drag options to blanks, or click blank then click option'
Aofficial/nginx
Bnginx/latest
Cnginx:latest
Ddocker/nginx
Attempts:
3 left
💡 Hint
Common Mistakes
Using slash instead of colon causes Dockerfile build errors.
Using non-existent image names causes build failure.
4fill in blank
hard

Fill both blanks to create a Docker command that runs Nginx in detached mode and removes the container after it stops.

Nginx
docker run [1] [2] nginx
Drag options to blanks, or click blank then click option'
A-d
B-rm
C--rm
D-it
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-rm' instead of '--rm' causes an error.
Using '-it' is for interactive mode, not detached.
5fill in blank
hard

Fill all three blanks to create a Docker command that runs Nginx, names the container 'mynginx', maps port 8081 on host to 80 in container, and mounts local directory '/home/user/site' to '/usr/share/nginx/html' inside container.

Nginx
docker run -d --name [1] -p [2]:80 -v [3]:/usr/share/nginx/html nginx
Drag options to blanks, or click blank then click option'
Amynginx
B8081
C/home/user/site
D/var/www/html
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping host and container ports in -p flag.
Using wrong local directory path for volume mount.

Practice

(1/5)
1. What is the primary purpose of the official Nginx Docker image?
easy
A. To quickly run Nginx inside a container for web serving
B. To build custom Linux kernels
C. To manage databases inside containers
D. To create virtual machines

Solution

  1. Step 1: Understand the role of Nginx

    Nginx is a web server used to serve websites and handle web traffic.
  2. Step 2: Recognize the Docker image purpose

    The official Nginx Docker image allows running Nginx easily inside containers for web serving.
  3. Final Answer:

    To quickly run Nginx inside a container for web serving -> Option A
  4. Quick Check:

    Official Nginx Docker image = Quick Nginx container [OK]
Hint: Nginx image runs web server in container fast [OK]
Common Mistakes:
  • Confusing Nginx with database or VM tools
  • Thinking it builds Linux kernels
  • Assuming it manages virtual machines
2. Which Docker command correctly runs the official Nginx image exposing port 80 on the host?
easy
A. docker run -p 80 nginx
B. docker run -p 8080:80 nginx
C. docker run -p 80:80 nginx
D. docker run nginx -p 80:80

Solution

  1. Step 1: Understand Docker port mapping syntax

    The correct syntax is docker run -p hostPort:containerPort image.
  2. Step 2: Match the command to expose port 80 on host

    docker run -p 80:80 nginx uses -p 80:80 which maps host port 80 to container port 80 correctly.
  3. Final Answer:

    docker run -p 80:80 nginx -> Option C
  4. Quick Check:

    Port mapping syntax = -p hostPort:containerPort [OK]
Hint: Use -p hostPort:containerPort to expose ports [OK]
Common Mistakes:
  • Omitting container port in -p option
  • Placing -p after image name
  • Using wrong port numbers
3. What will be the result of running this command?
docker run --rm -p 8080:80 nginx

Then accessing http://localhost:8080 in a browser?
medium
A. Connection refused error
B. You will see the default Nginx welcome page
C. 404 Not Found error
D. Docker container will fail to start

Solution

  1. Step 1: Analyze the Docker run command

    The command runs Nginx container mapping host port 8080 to container port 80, with --rm to remove container after exit.
  2. Step 2: Understand Nginx default behavior

    Nginx serves a default welcome page on port 80 if no custom config is provided.
  3. Final Answer:

    You will see the default Nginx welcome page -> Option B
  4. Quick Check:

    Default Nginx page served on mapped port [OK]
Hint: Default Nginx page shows if no config mounted [OK]
Common Mistakes:
  • Expecting 404 without custom config
  • Thinking container fails without volumes
  • Confusing port 80 with 8080 inside container
4. You tried to run:
docker run -p 80:80 nginx

but got an error: port is already allocated. What is the best fix?
medium
A. Stop the process using port 80 or use a different host port
B. Change the container port to 8080
C. Remove the Nginx image and pull again
D. Run the container without port mapping

Solution

  1. Step 1: Understand the error meaning

    "port is already allocated" means host port 80 is in use by another process.
  2. Step 2: Choose a fix for port conflict

    Stopping the process using port 80 or mapping to a different host port avoids conflict.
  3. Final Answer:

    Stop the process using port 80 or use a different host port -> Option A
  4. Quick Check:

    Port conflict fix = stop process or change host port [OK]
Hint: Port conflict means host port busy; change or free it [OK]
Common Mistakes:
  • Changing container port instead of host port
  • Deleting image won't fix port conflict
  • Running without port mapping disables access
5. You want to customize Nginx by using your own nginx.conf file located at /home/user/nginx.conf. Which Docker command correctly mounts this config into the container?
hard
A. docker run -v /etc/nginx/nginx.conf:/home/user/nginx.conf -p 8080:80 nginx
B. docker run -v /home/user/nginx.conf:/usr/local/nginx/nginx.conf -p 8080:80 nginx
C. docker run -v /home/user/nginx.conf:/etc/nginx/conf.d/nginx.conf -p 8080:80 nginx
D. docker run -v /home/user/nginx.conf:/etc/nginx/nginx.conf:ro -p 8080:80 nginx

Solution

  1. Step 1: Identify correct Nginx config path inside container

    The main config file path in official Nginx image is /etc/nginx/nginx.conf.
  2. Step 2: Use volume mount syntax to map host config

    Mount host file /home/user/nginx.conf to container path /etc/nginx/nginx.conf with read-only flag :ro.
  3. Final Answer:

    docker run -v /home/user/nginx.conf:/etc/nginx/nginx.conf:ro -p 8080:80 nginx -> Option D
  4. Quick Check:

    Mount host config to /etc/nginx/nginx.conf with :ro [OK]
Hint: Mount config to /etc/nginx/nginx.conf with :ro for safety [OK]
Common Mistakes:
  • Reversing source and target paths in -v option
  • Mounting to wrong container config directory
  • Omitting :ro to prevent accidental changes
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard