...

/

Build and Run a Container

Build and Run a Container

Get introduced to basic Docker commands to build an image and run a container.

Build a Docker image

Before you run a container, you first have to create an image. You can achieve that by using the docker build command. docker build creates an image from the Dockerfile.

Connect to the terminal via the terminal widget, which can be found at the end of this lesson. Once connected, the contents of the current directory will be displayed. You can observe that the Dockerfile is available in the directory.

To further inspect the Dockerfile, you can use the following command:

Press + to interact
nano Dockerfile

This will open up the Dockerfile in an editor. Once reviewed, you can exit the nano editor by using Ctrl-X on Windows or Control+X on Mac. Now, run the following command in the same directory as the Dockerfile:

Press + to interact
docker build -t ansible:latest .

You must be wondering what this flag -t ansible:latest does?

Docker uses tags to name and version container images. A tag consists of an image name and tag name. We provide the -t with the image and the tag name for that very ...