This document discusses Docker and provides an introduction and overview. It introduces Docker concepts like Dockerfiles, commands, linking containers, volumes, port mapping and registries. It also discusses tools that can be used with Docker like Fig, Baseimage, Boot2Docker and Flynn. The document provides examples of Dockerfiles, commands and how to build, run, link and manage containers.
2. Qui je suis
● Alexandre Salomé, développeur (180 mois)
● Consultant technique chez SensioLabs (66 mois)
● En mission chez Auchan e-commerce France (7 mois)
– Environnement totalement dockerisé
– Bientôt les serveurs de qualification
– Dans 3 ans en production ?
9. Show time !
La différence du dossier /etc entre :
- Ubuntu 14.10
- Ubuntu 12.10
docker run ubuntu:14.10 ls /etc > etc-14.10
docker run ubuntu:12.10 ls /etc > etc-12.10
meld etc-14.10 etc-12.10
11. Commandes usuelles
$ docker run --name=mon_redis redis
Donner un nom à son conteneur avec --name :
docker run redis
docker run ubuntu:14.10 ls /etc
12. Commandes usuelles
$ docker ps
CONTAINER ID IMAGE CREATED STATUS NAMES
eb232dde2f79 redis:latest 3 seconds ago Up 2 seconds mon_redis
$ docker ps -a
CONTAINER ID IMAGE CREATED STATUS PORTS NAMES
eb232dde2f79 redis:latest 2 minutes ago Up 2 minutes 6379/tcp mon_redis
b715035816d7 redis:latest 4 minutes ago Exited (0) 4 minutes ago sharp_wozniak
13. Commandes usuelles
$ docker logs mon_redis
[1] 14 Jan 19:35:02.096 # Warning: no config file specified, using the
default config. In order to specify a config file use redis-server
/path/to/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.17 (00000000/0) 64 bit
.-`` .-```. ```/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 1
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
15. Commandes usuelles
$ docker diff mon_redis
A /tmp/sess_b86hok0pfj23a81ea3flr0rk03
C /tmp/sess_esmblquiab21m995q2d195j1r5
D /tmp/sess_gl0cmpknk3rirc3l0jmjfd1bo1
C /tmp/sess_ql581nl6ac0uhaj47cftn8ipb7
Afficher le différentiel d'un conteneur :
16. Commandes usuelles
$ docker run -d --name=mon_redis redis
$ docker stop mon_redis
Démarrer en arrière plan avec -d :
Arrêter un conteneur :
18. Commandes usuelles
$ docker rmi redis
Supprimer une image
$ docker rm mon_redis
Supprimer un conteneur
$ docker stop mon_redis
Arrêter un conteneur
19. $ docker
Commands:
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders from a container's filesystem to the host path
diff Inspect changes on a container's filesystem
events Get real time events from the server
export Stream the contents of a container as a tar archive
history Show the history of an image
images List images
import Create a new filesystem image from the contents of a tarball
info Display system-wide information
inspect Return low-level information on a container
kill Kill a running container
load Load an image from a tar archive
login Register or log in to a Docker registry server
logout Log out from a Docker registry server
logs Fetch the logs of a container
port Lookup the public-facing port that is NAT-ed to PRIVATE_PORT
pause Pause all processes within a container
ps List containers
pull Pull an image or a repository from a Docker registry server
push Push an image or a repository to a Docker registry server
restart Restart a running container
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save an image to a tar archive
search Search for an image on the Docker Hub
start Start a stopped container
stop Stop a running container
tag Tag an image into a repository
top Lookup the running processes of a container
unpause Unpause a paused container
version Show the Docker version information
wait Block until a container stops, then print its exit code
21. Dockerfile
● Recette de construction d'un conteneur
● Format de fichier simple
FROM ubuntu:14.10
ENV APACHE_LOG_DIR /var/log/apache2
RUN apt-get install -y apache2
ADD site.conf /path/to/site.conf
EXPOSE 80
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
Exemple non fonctionnel, parce que Apache, c'est pas aussi simple
Dans cet exemple, le Dockerfile fait 5 lignes
28. Volumes
● Permet de partager des dossiers entre
les conteneurs et le système hôte
$ docker run
-v /home/alex/public:/var/www
my_apache
Le chemin sur mon système Le chemin dans le conteneur
29. Port mapping
● Permet d'exposer des ports du conteneur sur
l'hôte
$ docker run
-p 8000:80
my_apache
Le port sur mon système Le port dans le conteneur