The shipping industry standardized the container sizes, no matter what are the sizes of the user materials to be transported. This standardization resulted in upstream benefits of all the transportations to be standardized as well. Now, the only choice left is to determine what type of transportation to choose, land, air or water. All the transport media in a given mode of transport are already pre built to specific container sizes, which means improved efficiency and faster construction of these media.
Similarly, digital container exist, making the softwares portable to make them easy to run on any platform. This improves the deployment of a developed software from the developers machine to a virtual cloud, and across staging and production environments efficiently.
A container engine virtualizes the operating system. It is light-weight, fast, isolated, portable, secure and requires less memory space. Binaries/libraries within the container enable the apps to run, and a single machine can host multiple containers.
Containers are platform, operating system, and programming language independent.
Docker is the most popular software to run containerized applications. Its written in Go language and uses Linux kernel’s features to deliver functionality. It uses namespaces technology to provide isolated workspace called a container. It creates a set of namespaces for every container and each aspect runs in a separate namespace with access limited to that namespace.
hostname/repository:tag
Dockerfile
Docker file is a text file containing the instructions needed to create an image
FROM
command which defines the base imageRUN
is to execute arbitrary commandsCMD
is to run a shell command
CMD["echo", "Hello World!"]
for example to print Hello World.CMD
commandCMD
commands, only the last one will take effectWORKDIR
is to set the work directory for subsequent instructions, to simplify path referencesCOPY
instruction to copy a file from the local directory/machine to the container, can be a requirements.txt
file for installing dependencies
EXPOSE {port num}
can be used to expose a port that the container will listen on at runtimeLABEL
to add metadata to the image
LABEL version="1.0"
LABEL description="docker image desc"
LABEL maintainer="Your Name"
HEALTHCHECK
is optional, and can be used to ensure if the container is running correctly
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD curl -fs http://localhost:$PORT || exit 1
$PORT
is an environment variable referring to the port number the container will listen onUSER
USER node
will set a user named node
to run the subsequent commandsdocker build .
to build the image from the current directory dockerfile
docker build -t my-app:v1 .
where -t
is used to provide a tag, which is my-app
(the repository name) followed by the version, and the last .
is to refer to the current directorydocker run
followed by the image name
-p
to publish a portdocker push
and docker pull
are used to push and pull images from a configured registrydocker images
to list all the imagesdocker ps
to list the containers