Run Your First Container

DockerBeginner
Practice Now

Introduction

Welcome to the "Run Your First Container" challenge! You've already learned how to run the hello-world container. Now, let's take it a step further and run a different container. In this challenge, you'll use your Docker skills to start the docker/getting-started image, which launches a small web server inside a container.

Run a New Container

Tasks

Your task is simple:

  1. Run a Docker container based on the docker/getting-started image.

Requirements

To complete this challenge, you must:

  1. Use the docker run command to start the container.
  2. Use the image docker/getting-started, it has been pre-pulled for you.
  3. Execute the command in the ~/project directory.

Example

When you successfully run the container, Docker starts the container in the foreground, so your terminal stays attached to the container logs. Those logs come from the Nginx web server inside docker/getting-started.

Don't worry if you see a warning message about the /docker-entrypoint.d/ directory not being empty.

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/10/29 09:26:17 [notice] 1#1: using the "epoll" event method
2024/10/29 09:26:17 [notice] 1#1: nginx/1.23.3
2024/10/29 09:26:17 [notice] 1#1: built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r4)
2024/10/29 09:26:17 [notice] 1#1: OS: Linux 5.15.0-56-generic
2024/10/29 09:26:17 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024/10/29 09:26:17 [notice] 1#1: start worker processes
2024/10/29 09:26:17 [notice] 1#1: start worker process 31
2024/10/29 09:26:17 [notice] 1#1: start worker process 32

You can open a new terminal window to verify that the container is running by using the docker ps command.

docker ps
CONTAINER ID   IMAGE               COMMAND                  CREATED          STATUS          PORTS     NAMES
f3f3b3b3b3b3   docker/getting-started   "/docker-entrypoint.…"   1 minute ago   Up 1 minute   80/tcp   festive_mendel

Note: Keep the first terminal running after docker run docker/getting-started. If you press Ctrl+C or close that terminal, the container stops. Open a second terminal to run docker ps, or use docker run -d docker/getting-started if you want the container to run in the background.

Summary

In this challenge, you've expanded your Docker skills by running a new container. You've used the docker run command to start the docker/getting-started image, which launches a web server inside a container and prints its startup logs in the terminal. You also saw that a container started in the foreground keeps the terminal attached until you stop it. This exercise reinforces the basics of starting containers and checking whether they are running with Docker commands such as docker ps.

✨ Check Solution and Practice