Linux Labs

Containers: Docker and compose / Stage 2 of 11

Ports, variables and restart

Not running Starting usually ~20 s
Leave the lesson

Step 1 of 8 · on a machine · 5 min

The container runs, the site is silent

What you will learn

  • Publish a container port on a server port and check the publishing.
  • Pass environment variables to a container and see what the process got.
  • Choose a restart policy for the behaviour after a crash, docker stop and a docker service restart.

The company site has moved into the site container from the nginx:alpine image, which is the nginx web server on Alpine Linux. The site must open on port 8080 of the server: port 80 is taken by another web server. Here too the docker commands go through sudo.

Check whether the container is running and open the site. "Start" launches site the way a colleague launched it.

Exercise · look

Open the site from the container

Check whether the site container is running, then open the site on port 8080 of the server.

First, predict

The site container is running. What will curl print?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

site is Up in docker ps, yet curl to port 8080 of the server got Couldn't connect to server. Which of these is true?

  • docker ps shows site with the Up status: the container's main process is running.

  • There was no HTTP answer: (7) Couldn't connect to server means the connection never opened.

  • curl would wait for a dropped connection until a timeout, but the refusal came within a couple of milliseconds, which is how a port nobody listens on answers.

The container is running, but nothing accepts connections on port 8080 of the server.

Ubuntu 24.04
Loading…