- Series of command-line instructions to assemble the docker image
- A template/model that setups the environment and dependencies of the application as an isolated package
- It consists of a stack of layers; a layer is equivalent to a command-line instruction in Dockerfile
Layers
can be compared tocommits
in git (personal observation)- Your machine downloads these
layers
in docker cache - Only one copy of commit hash is downloaded and stored in docker cache. This saves up space in our host machine
- Image tag is like a pointer to a specific layer in an image
- Tags are greatly used for versioning
Sequence of commands is important as each command represents a layer in docker cache; place on top of the Dockerfile the commands that change the least, and at the bottom of the file the commands that change the most
Combine related and multiple commands in one layer. We use the
&&
to combine or chain one command after another. This saves time and space
- A running instance of an image
Containers
are immutable and ephemeral- They don't change; thus if change is needed, dispose the current and just deploy a new one
- how about persistent data? We use
Volumes
andBind Mounts
- volumes can outlive a container, this is good for persistent data such as
databases
- File sharing between a host and a Docker container
- Bind mount when you want a file or directory on the host machine to be mounted into a container
- As observed, we mount the source code of the application so the changes are immediately visible
- Configure relationships between containers
- Configure multiple containers in one file