Up to this point, we have:
- Learned to use Docker to run, start, stop, and delete containers
- Learned to use Docker to work with images: download, commit, delete
- Learned to use Docker-Compose so that multiple containers are able to work together, each having a single purpose
In this lab, we’ll look at another common technique you’ll run into on GitHub when docker is an option: the Dockerfile.
- The docker images you’ve been working with from Dockerhub were all built by someone using a Dockerfile. Once the image is built, an image can be made available so that other users can run containers from it.
Dockerfile facts
- The Dockerfile is a text file that (mainly) contains the instructions that you would execute on the command line to create an image.
- A Dockerfile is a step-by-step set of instructions.
- Docker provides a set of standard instructions for use in the Dockerfile, such as
FROM, COPY, RUN, ENV, EXPOSE, and CMD, to name a few basic ones.
- Docker will build a Docker image automatically by reading these instructions from the Dockerfile.
We will create our first Dockerfile.
- This is a pretty complicated process. So pay attention!
Here we go:
- Create a folder for this project
- cd into it
- Type:
touch Dockerfile
Whew! You made it. Congratulations. You just created your first Dockerfile! (Take a breather. That was rough, I know.)
Every Docker image must start with a base image pulled from Dockerhub. Several base images are available, but not all of them utilize the handy tools we are used to, like *apt install*. (You’ll find that as you pull specific Docker images, *apt install* is not present, and you’ll need to research what package manager you should be using instead.)