In the last lesson, you built your own image.
You can also download an image from Docker Hub, a public registry: a place that stores images.docker pull nginxdocker pulldownloads the image nginx from Docker Hub to your server.
nginx is a web server.
Figure 1 - docker pull Downloads an Image
When you give no tag, Docker uses the tag latest.
docker pull nginxanddocker pull nginx:latestdownload the same image.$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest d857fe34d5bc 9 days ago 192MBdocker imageslists the images of your server.
In the lab, download the imagenginxand list the images to get the flag.Answer the question below
Enter the flag you obtained.
docker runcreates a container from an image and starts it.
Figure 2 - The Parts of docker run
Without
-d, the container keeps your terminal busy.With
-d, it runs in the background, and you can type other commands.
docker pslists the running containers.
In the lab, start a container namedwebfrom the imagenginxin the background, then list the running containers to get the flag.Answer the question below
Enter the flag you obtained.
nginx listens on port 80 inside the container, so a request to your server does not reach the container.
The option-ppublishes a port: it links a port of your server to a port of the container.
Figure 3 - Port 8080 of the Server Leads to Port 80 of the Container
In
-p 8080:80, the first number is the port of your server.The second number is the port of the container.
You choose the published ports when you start the container, and you cannot add one later.
In the lab, start a container namedweb2from the imagenginxwith-dand-p 8080:80, then send the requestcurl localhost:8080to get the flag.Answer the question below
Enter the flag you obtained.
A container in the background prints nothing in your terminal.
docker logsdisplays what the application wrote, and nginx writes one line for each request:
Figure 4 - One Request in the Logs of nginx
When an application does not work, read its logs first.
In the lab, the containerwebnow publishes port 8080: send a request tolocalhost:8080, then display the logs of the containerwebto get the flag.Answer the question below
Enter the flag you obtained.
docker stopstops a container, but the container still exists, anddocker ps -alists it.docker rmremoves a stopped container.
Figure 5 - Stop a Container, Then Remove It
The image stays on your server, so you can start a new container from it at any time.
In the lab, stop the containerweb, list all the containers, then remove it to get the flag.In the next module, you will see how to protect an application and its data.
Answer the question below
Enter the flag you obtained.