Docker – Memo configuration

Schéma synthétisant le fonctionnement de Docker

(source krammark23 sur Youtube)

 

Documentation et références

 

Installation et configuration de Docker CE

Installation des pré-requis :

# apt-get update
# apt-get install apt-transport-https ca-certificates curl software-properties-common

Ajout du dépôt Docker et de sa clef GPG :

# curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
OK
# echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee -a /etc/apt/sources.list.d/docker.list
deb [arch=amd64] https://download.docker.com/linux/debian stretch stable
# apt-get update
[...]
Réception de:5 https://download.docker.com/linux/debian stretch InRelease [39,1 kB]
Réception de:7 https://download.docker.com/linux/debian stretch/stable amd64 Packages [3 610 B]
Réception de:8 https://download.docker.com/linux/debian stretch/stable amd64 Contents (deb) [1 314 B]
[...]

Installation de Docker CE à partir du dépôt Docker :

# apt-cache policy docker-ce
docker-ce:
  Installé : (aucun)
  Candidat : 18.03.1~ce-0~debian
[...]
# apt-get install docker-ce
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances       
Lecture des informations d'état... Fait
The following additional packages will be installed:
  aufs-dkms aufs-tools cgroupfs-mount git git-man liberror-perl pigz rsync
Paquets suggérés :
  aufs-dev git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-arch git-cvs git-mediawiki git-svn
Les NOUVEAUX paquets suivants seront installés :
  aufs-dkms aufs-tools cgroupfs-mount docker-ce git git-man liberror-perl pigz rsync
[...]

Activation du démon Docker au démarrage et du service :

# systemctl enable docker
Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable docker
# systemctl start docker

Vérification de l’installation :

# docker version
Client:
 Version:      18.03.1-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   9ee9f40
 Built:        Thu Apr 26 07:17:14 2018
 OS/Arch:      linux/amd64
 Experimental: false
 Orchestrator: swarm

Server:
 Engine:
  Version:      18.03.1-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.5
  Git commit:   9ee9f40
  Built:        Thu Apr 26 07:15:24 2018
  OS/Arch:      linux/amd64
  Experimental: false

Lancement du container hello-world pour test :

# docker container run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete 
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

Ajout de l’utilisateur local adminsys au groupe docker :

# getent group docker
docker:x:998:
# usermod adminsys -aG docker
# getent group docker
docker:x:998:adminsys

L’utilisateur adminsys doit fermer et rouvrir sa session.

Lancement de l’image Ubuntu avec terminal bash interactif :

$ docker container run -it ubuntu bash

 

Installation de Docker Machine sur Linux

Procédure d’installation sur GitHub : docker/machine – Releases

# curl -L https://github.com/docker/machine/releases/download/v0.15.0/docker-machine-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-machine \
&& chmod +x /usr/local/bin/docker-machine

 

(Optionnel) Ajout éventuel de scripts rendant l’utilisation de Docker Machine plus simple et modifiant le prompt : Install Docker Machine – Install bash completion scripts

$ sudo wget https://raw.githubusercontent.com/docker/machine/master/contrib/completion/bash/docker-machine-prompt.bash -O /etc/bash_completion.d/docker-machine-prompt.bash	 	 
$ sudo wget https://raw.githubusercontent.com/docker/machine/master/contrib/completion/bash/docker-machine-wrapper.bash -O /etc/bash_completion.d/docker-machine-wrapper.bash	 	 
$ sudo wget https://raw.githubusercontent.com/docker/machine/master/contrib/completion/bash/docker-machine.bash -O /etc/bash_completion.d/docker-machine.bash	 	 
$ echo 'PS1="[\u@\h \W$(__docker_machine_ps1)]\$ "' >> ~/.bashrc	 	 
$ source /etc/bash_completion.d/docker-machine-prompt.bash	 	 
$ source ~/.bashrc

 

Installation de Docker Compose sur Linux

Procédure d’installation sur GitHub : docker/compose – Releases

# curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose

 

Ajouter Dockerfile Syntax Highlighting sur Sublime Text 3

Tools > Commande Palette… > Package Control : Install Package > Dockerfile Syntax Highlighting
 

Installer le module python Pygments pour la coloration syntaxique du terminal

$ sudo apt-get install python-pip
$ pip install Pygments
$ sudo ln -s ~/.local/bin/pygmentize /usr/local/bin/pygmentize
$ pygmentize Dockefile
# this same shows how we can extend/change an existing official image from Docker Hub

FROM nginx:latest
# highly recommend you always pin versions for anything beyond dev/learn

WORKDIR /usr/share/nginx/html
# change working directory to root of nginx webhost
# using WORKDIR is preferred to using 'RUN cd /some/path'

COPY index.html index.html

# I don't have to specify EXPOSE or CMD because they're in my FROM

 

Références

Fermer le menu
%d blogueurs aiment cette page :