1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Docker

Connected

Exercise

Changing behavior when starting a container

Let's see how the ENV Dockerfile instruction works in practice. We've added a Dockerfile to your current working directory with the following instructions:

FROM ubuntu:22.04
ENV NAME=Tim
CMD echo "Hello, my name is $NAME"

The Dockerfile will print a personalized message, Hello, my name is Tim, on startup. Let's see how we can change this personalized message even after building an image from the Dockerfile.

Instructions 1/2

undefined XP
  • 1
    • Before we can start a container, we need to build the image from the Dockerfile. Build the Dockerfile in your local working directory giving it the name hello_image.
  • 2
    • Now that we've built the image, we can start a container from it. Start a container from the hello_image image you just made, but use a flag on the command to set the NAME ENV variable to your name.