Running containers

Start containers and see what is running.

A Docker practice simulator runs inside your browser tab. It behaves like the real commands for what the lessons teach, and it is labelled as a simulation.

docker run starts a container

docker run creates a container from an image and starts it. If the image is not on your computer yet, Docker pulls it first.

-d runs the container in the background and prints its id, so your terminal stays free. Servers such as nginx are run this way.

docker ps lists the containers that are running.

Example
docker run -d nginx
docker ps

Some containers finish and stop

A container runs for as long as its main program runs. A web server keeps going. A program that prints a message finishes at once, and its container stops.

A stopped container still exists. docker ps hides it; docker ps -a shows every container, running or stopped.

Example
docker run hello-world
docker ps -a

Your turn: a background server

The container should still be running when your commands finish.

Practice task

Start an nginx container in the background.

Your answer is run and checked in the lesson. Create a free account to try it.

Reading a container's output

A background container prints nothing to your terminal. docker logs shows what it has printed so far, which is the first place to look when something is wrong.

You name the container by its name or by the first few characters of its id. The next topic covers choosing names.

Example
docker run -d --name web nginx
docker logs web

Your turn: two servers

Each docker run starts one container.

Practice task

Start two background containers: one from redis and one from nginx.

Your answer is run and checked in the lesson. Create a free account to try it.