What is Docker?#
“Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications.” ~ Docker Docs
What is an image?#
An image is a read-only template of instructions for creating a Docker container. Images usually contain other images with customisation. Images can be customised and configured using a
What is a Container?#
A container is a runnable instance of an image. It can be started, stopped, restarted, moved, or deleted.
Start / Stop / Restart#
Note: Usually the first 3/4 characters of the ID is enough to identify the image.
docker start <ID> docker stop <ID> docker restart <ID>
Remove all images#
docker images -q docker rmi $(docker images -q)
Remove all containers#
docker ps -q # list all the container IDs docker rmi $(docker ps -a -q) # remove all containers
Determines the image source which the resulting image will be created FROM.
For example to create a linux machine image:
FROM httpd:alpine AS base # `AS` is used to give a name for # later use if required.
Copies the contents into the image. Wildcards and location specifications can be used. COPY creates a new layer.
COPY /<source_directory/ /destination_directory/ COPY *.png /images/ COPY --from=<imageAlias> /usr/local/apache2/htdocs/ /app/ # The --from flag allows us to copy from one image to another
This sets the working directory inside the container. It sets a path to be used as a starting point. If the path doesn’t exist,
WORKDIR will create the path. All relative paths from this point will be inside the
ENV allows for setting environment variables in the dockerfile using a key value.
ENV DIRPATH /usr/local/apache2 ... WORKDIR $DIRPATH/htdocs/
This is just documentation. It doesn’t do anything. It doesn’t publish, it informs the container user of the ports that the image intends to use. It can be overridden by the
docker run -p flag.
RUN, runs a one-off command on the image. It creates a new layer in the image.
Creates a file location in the container that lives outside the container on your machine. This provides a persistent storage independent of the image.
FROM ubuntu RUN mkdir /myvol RUN echo "hello world" > /mvol/greeting VOLUME /myvol
The location of the column on the local machine can be configured under the docker run cli command.
The entry point specifies that we are going to run something when the container starts.
ENTRYPOINT [ "/app/entrypoint.sh"] # start this shell file CMD [ "server" ] # The argument to be passed to the # entrypoint, can be overridden from the # docker run command.