How can you customize the Nginx configuration in the official Docker image?
You can mount your own configuration file into the container using a volume, for example: docker run -v /my/nginx.conf:/etc/nginx/nginx.conf:ro nginx.
Click to reveal answer
beginner
What is the default port exposed by the Official Nginx Docker image?
Port 80 is the default port where Nginx listens inside the container.
Click to reveal answer
Which command starts an Nginx container exposing port 80 inside the container to port 8080 on your host?
Adocker run -p 8080:8080 nginx
Bdocker run -p 8080:80 nginx
Cdocker run -p 80:80 nginx
Ddocker run -p 80:8080 nginx
✗ Incorrect
The syntax is -p hostPort:containerPort. So -p 8080:80 maps container port 80 to host port 8080.
Where is the Official Nginx Docker image hosted?
ANginx official website
BGitHub
CDocker Hub
DAWS Marketplace
✗ Incorrect
Official Docker images are hosted on Docker Hub, including the Nginx image.
How can you provide a custom Nginx configuration file to the container?
ABy mounting a volume with the config file
BBy editing the container's internal files directly
CBy passing config as a command line argument
DBy rebuilding the Docker image only
✗ Incorrect
Mounting a volume with your config file is the easiest way to customize Nginx without rebuilding the image.
What is the default command run by the Official Nginx Docker image?
Anginx -g 'daemon off;'
Bnginx -s reload
Cbash
Dservice nginx start
✗ Incorrect
The image runs Nginx in the foreground with nginx -g 'daemon off;' to keep the container running.
Which port does Nginx listen to inside the container by default?
A443
B22
C8080
D80
✗ Incorrect
Nginx listens on port 80 by default inside the container.
Explain how to run the Official Nginx Docker image and access it from your browser.
Think about how ports inside and outside the container connect.
You got /3 concepts.
Describe how to customize the Nginx configuration when using the Official Docker image.
Consider how files from your computer can be shared with the container.
You got /3 concepts.
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
Step 1: Understand the role of Nginx
Nginx is a web server used to serve websites and handle web traffic.
Step 2: Recognize the Docker image purpose
The official Nginx Docker image allows running Nginx easily inside containers for web serving.
Final Answer:
To quickly run Nginx inside a container for web serving -> Option A
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
Step 1: Understand Docker port mapping syntax
The correct syntax is docker run -p hostPort:containerPort image.
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.
Final Answer:
docker run -p 80:80 nginx -> Option C
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
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.
Step 2: Understand Nginx default behavior
Nginx serves a default welcome page on port 80 if no custom config is provided.
Final Answer:
You will see the default Nginx welcome page -> Option B
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
Step 1: Understand the error meaning
"port is already allocated" means host port 80 is in use by another process.
Step 2: Choose a fix for port conflict
Stopping the process using port 80 or mapping to a different host port avoids conflict.
Final Answer:
Stop the process using port 80 or use a different host port -> Option A
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