We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Dockerfiles

Docker isn't only useful for running other people's software (as we've been doing so far). It's also a great way to build and package our own software.

I've used Docker both ways. As a DevOps/platform engineer I'm usually using other's images, but as a backend developer I was usually building images for our own servers.

Docker images are built from Dockerfiles. A Dockerfile is just a text file that contains all the commands needed to assemble an image. It's essentially the "Infrastructure as Code" (IaC) for an image. It runs commands from top to bottom, kind of like a shell script.

Instead of manually installing dependencies on servers and making updates manually, we can check a Dockerfile into source control and build it automatically. Mhmmmm, automation.

Assignment

# This is a comment

# Use a lightweight debian os
# as the base image
FROM debian:stable-slim

# execute the 'echo "hello world"'
# command when the container runs
CMD ["echo", "hello world"]
docker build . -t helloworld:latest

The -t helloworld:latest flag tags the image with the name "helloworld" and the "latest" tag. Names are used to organize your images, and tags are used to keep track of different versions.

docker run helloworld

If all went well, you'll see "hello world" printed to the console!

Run and submit the CLI tests.