Dockerfiles describe how to build docker images
docker build -t tagName .
build an image from the dockerfile in the current folder and call is tagName
Each line make a new image that is used in the subsequent step. So if your program downloads a big file then the next line only uses a small bit of it the image will include the big image. Otherwise, if your program downloaded a big image and used a small bit of it on the same line the image only includes the small bit. Much better
Previous image is not modified. So if there is no change that step is not rerun. Put the parts of the code that change the most at the end of the docker file so you can leverage this feature. Note, if you want to redo an part of the code, where things didn't change, you must tell docker as it will otherwise skip it
Dockerfiles are NOT shell scripts
Processes started on one line will not be running on the next line. Each line is it's own call to docker run and then docker commit.
Environment variables are available on subsquent lines and in the docker image
- ADD adds files to the points in the file system in many different ways
- CMD specifies a whole command to run when a container is started. User provided args replace CMD
- FROM must be the first command in the Dockerfile. Specifies images to start from
- ENTRYPOINT specifies the start of a command to run when an image is run, i.e. user args will be args to the entrypoint defined command. It make the image act like a program, otherwise use cmd
- EXPOSE maps a port into a container, like the -p flag
- MAINTAINER specifies the image maintainer
- RUN runs a command, waits for it to finish and saves the result
- VOLUME create shared or ephemeral volumes. You don't want to use shared volumes as they can't be shared as they depend upon a specific folder on your machine
- WORKDIR sets the working directory for remainder of the dockerfile and the resulting container when you run it. Like running cd before every expression USER specifies the username or number
nano notes.txt
# runs bash that runs the shell command
["/bin/nano", "notes.txt"]
# Exec form is slightly faster as the shell is not involved