Docker is an open source software allowing to facilitate the deployment of isolated applications in software containers to be operated in various environments. Docker is a tool often used in development environments in order to solve integration issues (CI) and continuous deployment (CD).
Unlike virtual machines relying on a physical infrastructure, Docker affords to mutualize the physical layer and the operating system layer by wrapping the application and its dependencies (libraries, configuration files …). Advantages : only one OS to administrate, all containers are isolated.
Here are pictures of the difference between Container and VM:
A public register maintained by an active community allows Docker to make available containers ready to be quickly operated.
Docker is based on LXC (Linux Containers) and includes the following elements :
Functionality of the Linux kernel to limit, count and isolate resources (CPU, RAM, etc.) used by a process group.
Advanced management of permissions both at the applications’ level and the files system level.
Functionality of the Linux kernel allowing isolation, in order to ensure that a container can not affect another.
Functionality allowing to change a process root, in order to isolate it in a system as a security measure.
Docker provides services to simply perform différent actions: create, edit, publish and operate containers. You often hear about containers, images and DockerFile :
Source file containing instructions, elements to install, it is a configuration file.
Compilation of a DockerFile file to create a portable image, ready to be deployed
Execution of an image, container loading of an image
In order to install Docker on Debian 8, you only need to go through the management tool for packages :
apt-get update apt-get install docker.io
On Debian 7, it is essentiel to add the source deb http://http.debian.net/debian wheezy-backports main in the file sources.list.
Then we can operate the following commands tu update our source list, install wheezy-backports :
apt-get update apt-get install -t wheezy-backports linux-image-amd64
Install Docker thanks to the following command for script execution :
curl -sSL https://get.docker.com/ | sh
Once Dock installed, you just have to launch the service :
service docker start
Creation of a container
In this example, we will install a container Nginx from the images available in the Docker warehouses :
# docker search nginx
Please think about directing your choice between the description, the popularity and whether it is an official container or not.
We are going to repatriate the official Nginx container image :
# docker pull nginx
We check our image list:
# docker images
We can see that it was successfully repatriated :
REPOSITORY TAG IMAGE ID nginx latest cc1b61406712
We install the container :
# docker run -d -name=MyServerNginx nginx:latest
We check how well the container is installed :
# docker ps -a
This way, you can see your container operated (below is the detail of the command docker ps) then we start our container :
# docker start
By default, Docker uses NAT to match input ports on the server returned to listening ports of different containers with the option -p :
# docker run -p <host_port1>: -p <host_port2>:
The host port matches the port on which you have to contact the host to have access to the service, the container port matches the port to which the request will be redirected at the container’s level.
We are going to create a second container by adding this argument :
# docker run -d -p 1234:80 -name=MyServerNginx2 nginx:latest
You are aware of the service as being active by opening your web browser on http://IP_HOTE:1234
You can create your own container from a configuration file appointed DockerFile.
We are going to create a Debian container and install a server Apache2 accessible from outside.
Here is the DockerFile file’s content
### Image FROM debian:stable ### Information about the container's owner MAINTAINER email@example.com ### Command RUN only used during a container creation (needs a docker build) RUN apt-get update && apt-get upgrade -y && apt-get install -y apache2 ### Creation variable ENV VARIABLE ma-variable ### PORT 80 Open EXPOSE 80 ### We expose the SSH port to be able to connect with the machine EXPOSE 22 ### Command placed once the container is created (does not need a docker build, but a run) ### Command 1st arg 2nd arg CMD [« /usr/sbin/apache2ctl », »-D », »FOREGROUND »]
Now we can create our container from the Dockerfile with this command :
# docker build -t MyApache
We install our container by mapping the port 555 of the host towards the port http of the container :
# docker run -d -p 5555:80 -name=MyServerApache MyApache:latest
From now on, you can check the apache server access from this URL : http://IP_HOTE:5555
The following command can display the running containers list :
Personal identifier of the container’s image.
Command placed as parameter when the container was created
Date of creation of the container.
The different redirections of configured ports.
Random name given to the container, this is customizable thanks to the option -name during the execution docker run.
Here are some useful commands :
### restart a container docker start ### Stop a container docker stop ### List your repatriated images docker images ### Display the container's informations, including the virtual IP interface of the container for instance docker inspect ### Delete all active containers docker rm $(docker ps -a -q) ### Delete a docker image (check none of them is activated) docker rmi ### To directly connect on your container docker run -it /bin/bash
You can find all the docker images on https://hub.docker.com/explore/
You can find all the commands linked to docker in the assistance service :