Skip to content

Latest commit

 

History

History
859 lines (848 loc) · 28.3 KB

RESUME.md

File metadata and controls

859 lines (848 loc) · 28.3 KB

alt text

1. CREATION DE LA VM

alt text Notre machine virtuelle se nommera "mpdocker" elle sera le host qui permettra de faire fonctionner nos conteneurs.

Prerequis:

  • Une machine local sous Linux, Windows, MacOS
  • Avoir une connexion reseau
  • Installation de Vagrant et VirtualBox
  • Savoir utiliser Powershell
  • Avoir un editeur de texte (Notepad++, VSCode)
  • Creation d'une virtual machine avec un OS:Centos 7.6 depuis un vagrantfile
  • Le provisionement du syteme doit avoir au minimun ses paquets d'installer: git, docker, docker-compose

Depuis votre machine local (Host):

  1. Creation d'un dossier qui va contenir mon vagrantfile
PS H:\PROJETS\repo\student-list>
mkdir H:\PROJETS\repo\student-list\mpdocker\
  1. Initialisation d'un vagrantfile (option -m = configuration minimum)
PS H:\PROJETS\repo\student-list\mpdocker>
vagrant init -m
  1. Copier/Coller ce vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

RAM = 2048
CPU = 2
IP = "10.0.0.200"

# Check Vagrant plugins
# If you want to ensure that vagrant-winnfsd is installed and enabled every time you run your vagrant box, just add the following to your vagrant file, just before the code block
if Vagrant::Util::Platform.windows? then
  unless Vagrant.has_plugin?("vagrant-winnfsd")
    raise  Vagrant::Errors::VagrantError.new, "vagrant-winnfsd plugin is missing. Please install it using 'vagrant plugin install vagrant-winnfsd' and rerun 'vagrant up'"
  end
end
# If you want to ensure that vagrant-vbguest is installed and enabled every time you run your vagrant box, just add the following to your vagrant file, just before the code block
if Vagrant::Util::Platform.windows? then
  unless Vagrant.has_plugin?("vagrant-vbguest")
    raise  Vagrant::Errors::VagrantError.new, "vagrant-vbguest plugin is missing. Please install it using 'vagrant plugin install vagrant-vbguest' and rerun 'vagrant up'"
  end
end
# If you want to ensure that vagrant-share is installed and enabled every time you run your vagrant box, just add the following to your vagrant file, just before the code block
if Vagrant::Util::Platform.windows? then
  unless Vagrant.has_plugin?("vagrant-share")
    raise  Vagrant::Errors::VagrantError.new, "vagrant-share plugin is missing. Please install it using 'vagrant plugin install vagrant-share' and rerun 'vagrant up'"
  end
end
# SCRIPT for provisioning the magic system :)
$no_update_system = <<SCRIPT
echo Stop Update System...
sudo systemctl stop packagekit.service && sudo systemctl disable packagekit.service
echo "For this virtual machine, no update will be made the version Centos 7.6 will remain fixed"
SCRIPT

$install_git = <<SCRIPT
sudo yum install -y yum-utils
echo Install and configure git...
sudo yum install git -y
git config --global user.name "christophe-freijanes"
git config --global user.email "cfreijanes@gmx.fr"
git config --global core.editor vi
sleep 5
SCRIPT

$install_docker_script = <<SCRIPT
echo Installing Docker...
curl -sSL https://get.docker.com/ | sh
sudo usermod -aG docker $USER
sudo systemctl enable docker
sudo systemctl start docker
echo Docker has been installed...
echo Installing Docker-compose...
sudo mkdir -p /opt/bin/
sudo curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
echo Docker-Compose has been installed...
echo "For this Stack, you will use $(ip -f inet addr show eth1 | sed -En -e 's/.*inet ([0-9.]+).*/\1/p') IP Address"
sleep 5
echo "The Virtual machine Centos 7.6 has been installed >>> Last reboot !!!"
sudo reboot
SCRIPT

# The vagrant config for virtual machine named mpdocker
Vagrant.configure('2') do |config|
  config.vm.define :mpdocker, primary: true  do |mpdocker|
    mpdocker.vm.box = "komlevv/centos-7.6"
    mpdocker.vm.box_version = "1.0.0"
    mpdocker.vbguest.auto_update = false
    mpdocker.vm.network :private_network, ip: IP
#    mpdocker.vm.network :forwarded_port, guest: 5000, host: 5000
#    mpdocker.vm.network :forwarded_port, guest: 80, host: 8080
    mpdocker.vm.hostname = "mpdocker"
    mpdocker.vm.synced_folder ".", "/vagrant"
    mpdocker.vm.provision "shell", inline: $install_git, privileged: true
    mpdocker.vm.provision "shell", inline: $install_docker_script, privileged: true
    mpdocker.vm.provider "virtualbox" do |vb|
      vb.name = "mpdocker"
      vb.memory = RAM
  	  vb.cpus = CPU
    end
  end
end
  1. Installation des plugins vagrant
PS H:\PROJETS\repo\student-list\mpdocker>
vagrant plugin install vagrant-winnfsd
PS H:\PROJETS\repo\student-list\mpdocker>
vagrant plugin install vagrant-vbguest
PS H:\PROJETS\repo\student-list\mpdocker>
vagrant plugin install vagrant-share
  1. Verification de son vagrantfile
PS H:\PROJETS\repo\student-list\mpdocker>

Output:

vagrant validate
Vagrantfile validated successfully.
  1. Creation de la machine virtuelle "mpdocker"
PS H:\PROJETS\repo\student-list\mpdocker>
vagrant up
  1. Connexion en ssh depuis votre prompt
PS H:\PROJETS\repo\student-list\mpdocker>
vagrant ssh mpdocker
  1. Verification apres installation
cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
docker -v
Docker version 20.10.10, build b485636
docker-compose -v
docker-compose version 1.29.2, build 5becea4c
ip a
...
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:24:c7:d8 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.200/24 brd 10.0.0.255 scope global noprefixroute eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe24:c7d8/64 scope link
       valid_lft forever preferred_lft forever
...

2. RECUPERATION DU CODE

alt text

  1. Depuis mpdocker (Host) copier le code de l' API a la racine "/"
cd /
sudo git clone https://github.com/diranetafen/student-list.git
  1. Verification de l'emplacement du code
ls -alh /student-list/

Output:

total 48K
drwxr-xr-x.  8 root root  193 Nov 11 13:52 .
dr-xr-xr-x. 19 root root  259 Nov 11 13:52 ..
-rw-r--r--.  1 root root  800 Nov 11 13:52 docker-compose.yml
drwxr-xr-x.  8 root root  163 Nov 11 13:52 .git
-rw-r--r--.  1 root root 7.1K Nov 11 13:52 README.md
drwxr-xr-x.  2 root root   70 Nov 11 13:52 simple_api
drwxr-xr-x.  2 root root   23 Nov 11 13:52 website

3. CREATION DU DOCKERFILE

alt text

  1. Edition du Dockerfile
sudo vi /student-list/simple_api/Dockerfile

NB: La touche I c'est la vie ! :)

FROM python:2.7-stretch
LABEL maintainer=Christophe-Freijanes mail=cfreijanes@gmx.fr  
# Dependencies for the system
RUN DEBIAN_FRONTEND=noninteractive apt-get update -y && apt-get install python-dev python3-dev libsasl2-dev python-dev libldap2-dev libssl-dev -y
# Installation Flask
RUN pip install flask==1.1.2 flask_httpauth==4.1.0 flask_simpleldap python-dotenv==0.14.0
# Configure network for API
EXPOSE 5000
# Configuration volume /data
VOLUME [ "/data" ]
# Copy the script student_age.py to /
COPY student_age.py /
# Run the server python and start api
CMD [ "python", "./student_age.py" ]

4. EDITION INDEX.PHP

  1. Edition de la page index.php
sudo vi /student-list/website/index.php
  1. Modifer les lignes suivantes
  $username = getenv('USERNAME');
  $password = getenv('PASSWORD');
  if ( empty($username) $username = 'Y29kYWMtcm8=';
  if ( empty($password) $password = 'IUMwZEBjUjA=';
  $context = stream_context_create(array(
    "http" => array(
    "header" => "Authorization: Basic " . base64_decode("$username:$password"),
  )));

Lien pour encoder ou decoder un mot de passe: Encode-Decode Base64

$url = 'http://<api_ip_or_name:port>/pozos/api/v1.0/get_student_ages';
par
$url = 'http://10.0.0.200:5000/pozos/api/v1.0/get_student_ages';
  1. Enregistrer les modifications part 1 ;)

5. EDITION DU FICHIER DES VARIABLES

  1. Creation et edition d'un fichier contenant les variables
sudo vi /student-list/.env_prod
SOME_USERNAME=toto
SOME_PWD_VAR=python
  1. Enregistrer les modifications ;)

6. CREATION VOLUME

  1. Creation d'un volume persistant
sudo docker volume create data
  1. Lister les volumes
sudo docker volume ls
DRIVER    VOLUME NAME
local     data
  1. Detail du volume data
sudo docker volume inspect data

Output :

[
    {
        "CreatedAt": "2021-11-07T17:46:02Z",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/data/_data",
        "Name": "data",
        "Options": {},
        "Scope": "local"
    }
]

7. CREATION NETWORK

  1. Creation d'un reseau pour permettre aux conteneurs de communiquer entre eux
sudo docker network create study-net

Exemple output :

93acfcd1907eb7cda5c5cb01c73750522abd1505703eba12a07a5069a12f1685
  1. Liste des network disponible
sudo docker network ls
NETWORK ID     NAME        DRIVER    SCOPE
8740347493ef   bridge      bridge    local
752df8a6eaeb   host        host      local
d4795f64a489   none        null      local
93acfcd1907e   study-net   bridge    local

8. BUILD AND RUN DOCKER IMAGE

alt text

  1. Creation de l'image pour notre conteneur api
cd /student-list/simple_api/
sudo docker build -t student-list_api:v1.0 .
  1. Verification de l'image
sudo docker images
REPOSITORY         TAG           IMAGE ID       CREATED         SIZE
student-list_api   v1.0          4c056fe48362   6 seconds ago   1.13GB
python             2.7-stretch   e71fc5c0fcb1   18 months ago   928MB
  1. Tag de l'image de l'apllication
sudo docker tag <IMAGE ID> cfreijanes/student-list_api:v1.0
  1. Creation d'un repositorie depuis son docker-hub

Lien : Docker-Hub repositories

alt text

alt text

  1. Connexion au Docker-hub
sudo docker login -u <USERNAME> -p <PASSWORD>
  1. Push de l'image vers le repositorie de son docker-hub
sudo docker push cfreijanes/student-list_api:v1.0
  1. Verification de nos microservices actifs ou non
sudo docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
  1. Creation du deuxieme conteneur student-list_web
  • Demarrer l'image docker
  • Creation et execution du conteneur student-list_web puis execution du conteneur contenant notre API
sudo docker run -it --name student-list_web --network study-net -d -p 8080:80 -v /website:/var/www/html/ php:apache
sudo docker run -it --name student-list_api --network study-net -d -p 5000:5000 -v /student-list/simple_api/student_age.json:/data/student_age.json student-list_api:v1.0
  1. Verification de nos microservices actifs
sudo docker ps -a
$ sudo docker ps -a
CONTAINER ID   IMAGE                   COMMAND                  CREATED          STATUS          PORTS                                       NAMES
f86db3416969   student-list_api:v1.0   "python ./student_ag…"   9 seconds ago    Up 8 seconds    0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   student-list_api
807d1dcdbd88   php:apache              "docker-php-entrypoi…"   35 seconds ago   Up 34 seconds   0.0.0.0:8080->80/tcp, :::8080->80/tcp       student-list_web
  1. Test de l'API
curl -u toto:python -X GET http://$HOSTNAME:5000/pozos/api/v1.0/get_student_ages
{
  "student_ages": {
    "alice": "12",
    "bob": "13"
  }
}

9. AUTOMATISATION AVEC GITHUB

alt text

Prerequis :

  • Avoir un compte Docker-hub permettant le build (payant).
  • Avoir creer une image depuis votre host.
  • Avoir pusher cette image sur votre repository Docker-hub.
  • Avoir un repository sur Github dans lequel sera construite votre Dockerfile. Dans cet exemple j'ai creer un repository docker-pozos sur mon Github.

Depuis son PC local vers Github

  1. Cloner le repository que vous venez de creer depuis votre Github
git clone git@github.com:christophe-freijanes/docker-pozos.git
  1. Depuis le prompt on ce rends dans notre repertoire
 cd .\docker-pozos\
  1. On va rendre dynamique le build de notre Dockerfile, biensur pour que cela fonctionne vous devez avoir le Dockerfile, student_age.py et student_age.json entre votre machine local et votre VM. Utiliser un editeur de text pour copier coller votre code et l'enregistrer.
FROM python:2.7-stretch
LABEL maintainer=Christophe-Freijanes mail=cfreijanes@gmx.fr  
# Dependencies for the system
RUN DEBIAN_FRONTEND=noninteractive apt-get update -y && apt-get install python-dev python3-dev libsasl2-dev python-dev libldap2-dev libssl-dev -y
# Installation Flask
RUN pip install flask==1.1.2 flask_httpauth==4.1.0 flask_simpleldap python-dotenv==0.14.0
# Configure network for API
EXPOSE 5000
# Configuration volume /data
VOLUME [ "/data" ]
# Copy the script student_age.py to /
COPY student_age.py /
# Run the server python and start api
CMD [ "python", "./student_age.py" ]
  1. Commande git a executer pour pusher le repo local
git init
git add Dockerfile README.md student_age.py student_age.json
git commit -am "Creation repo docker-pozos"
git remote add origin https://github.com/christophe-freijanes/docker-pozos.git
git push -u origin master

Depuis Docker-Hub vers Github

  1. Choisir le repository ou ce situe votre image

alt text 2. Parametrage a faire depuis votre compte

alt text

  1. Connexion a faire entre votre Github et Docker-Hub

alt text

  1. Aller dans votre repository contenant votre image

alt text

  1. Parametrage de votre Builds

alt text

  1. Choisir le repository de Github que vous souhaitez synchroniser

alt text

  1. Il ne reste plus cas faire ???

alt text

NB: Attention ne fermer pas la page cela peut-etre long, tout depend de la taille de l'image of course ;)

  1. Si le build ne se fait pas verifier depuis les settings que le lien vers votre Docker-hub et votre Github est implementer

alt text

10. NETTOYAGE

  1. Lister les conteneurs
sudo docker ps -a
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS         PORTS                                       NAMES
4d3626d0af8c   student-list_api:v1.0   "python ./student_ag…"   3 minutes ago   Up 3 minutes   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   student-list_api
a01dcea3b59d   php:apache            "docker-php-entrypoi…"   8 minutes ago   Up 8 minutes   0.0.0.0:8080->80/tcp, :::8080->80/tcp       student-list_web
  1. Stopper les conteneurs a nettoyer
sudo docker ps
sudo docker stop student-list_web
sudo docker stop student-list_api
  1. Suppression des conteneurs et des images
  • Supprimer les deux conteneurs
docker rm <CONTAINER ID>
docker images
  • Supprimer les 4 images de haut en bas c'est mieux :)
docker rmi <IMAGE ID>
  1. Verification que les conteneurs ne sont plus present
sudo docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
  1. Verification que les images ne sont plus presentes
sudo docker images
REPOSITORY         TAG           IMAGE ID       CREATED         SIZE

11. BUILD AND RUN DOCKER-COMPOSE

alt text

  1. Edition du docker-compose
cd ..
sudo vi docker-compose.yml
version: '3.3'
services:
    api:
        build: '/student-list/simple_api/'
        container_name: student-list_api
        network_mode: study-net
        ports:
            - '5000:5000'
        env_file:
            - .env_prod
        volumes:
            - '/student-list/simple_api/student_age.json:/data/student_age.json'
            - '/student-list/simple_api/student_age.py:/data/student_age.py'
    web:
        container_name: student-list_web
        network_mode: study-net
        ports:
            - '8080:80'
        env_file:
            - .env_prod
        volumes:
            - '/website:/var/www/html/'
        image: 'php:apache'
        depends_on:
            - 'api'
networks:
    study-net:

Lien : Composerize

  1. Run le docker-compose
sudo docker-compose up -d
Creating student-list_api_1 ... done
Creating student-list_web_1 ... done
  1. En cas d'erreur de votre commande "command not found"
  • Reinstallation de "docker-compose" pour Centos 7.6.
  • Pour une raison obscure, il arrive parfois qu'avec cette version de Centos 7.6, de rencontrer une erreur du type "command not found", lors de l'execution de cette commande :
sudo docker-compose up -d
  • Pour resoudre ce probleme suivre les etapes suivantes:
sudo curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version

Output:

docker-compose version 1.21.0, build 5920eb0
  • Si pas d'erreur Next step :)

Source : Docker Compose

  1. Verification de nos microservices
docker ps -a
CONTAINER ID   IMAGE              COMMAND                  CREATED         STATUS         PORTS                                       NAMES
78378f485a3e   php:apache         "docker-php-entrypoi…"   2 minutes ago   Up 2 minutes   0.0.0.0:8080->80/tcp, :::8080->80/tcp       student-list_web_1
e247a778b5c3   student-list_api   "python ./student_ag…"   2 minutes ago   Up 2 minutes   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   student-list_api_1

alt text

Congratulation !

12. PRIVATE DOCKER-REGISTRY

alt text

  1. Deployer d'une autre machine virtuelle dans cet exemple on la nommera "regdocker"
# -*- mode: ruby -*-
# vi: set ft=ruby :

RAM = 4096
CPU = 4
IP = "10.0.0.201"

# Check Vagrant plugins
# If you want to ensure that vagrant-winnfsd is installed and enabled every time you run your vagrant box, just add the following to your vagrant file, just before the code block
if Vagrant::Util::Platform.windows? then
  unless Vagrant.has_plugin?("vagrant-winnfsd")
    raise  Vagrant::Errors::VagrantError.new, "vagrant-winnfsd plugin is missing. Please install it using 'vagrant plugin install vagrant-winnfsd' and rerun 'vagrant up'"
  end
end
# If you want to ensure that vagrant-vbguest is installed and enabled every time you run your vagrant box, just add the following to your vagrant file, just before the code block
if Vagrant::Util::Platform.windows? then
  unless Vagrant.has_plugin?("vagrant-vbguest")
    raise  Vagrant::Errors::VagrantError.new, "vagrant-vbguest plugin is missing. Please install it using 'vagrant plugin install vagrant-vbguest' and rerun 'vagrant up'"
  end
end
# If you want to ensure that vagrant-share is installed and enabled every time you run your vagrant box, just add the following to your vagrant file, just before the code block
if Vagrant::Util::Platform.windows? then
  unless Vagrant.has_plugin?("vagrant-share")
    raise  Vagrant::Errors::VagrantError.new, "vagrant-share plugin is missing. Please install it using 'vagrant plugin install vagrant-share' and rerun 'vagrant up'"
  end
end

Vagrant.configure("2") do |config|
  config.vm.define "regdocker" do |regdocker|
    regdocker.vm.box = "ubuntu/xenial64"
    regdocker.vm.network "private_network", ip: IP
	  regdocker.vm.hostname = "regdocker"
    regdocker.vm.provider "virtualbox" do |v|
  	  v.name = "regdocker"
  	  v.memory = RAM
  	  v.cpus = CPU
  	end
  	regdocker.vm.provision :shell do |shell|
  	  shell.path = "install_docker.sh"
    end 
  end
end
  • A mettre dans le dossier de votre machine le script bash install_docker.sh a coter de votre vagrantfile ;)
#!/bin/bash
sudo yum -y update

# install docker
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
sudo usermod -aG docker vagrant
sudo systemctl enable docker
sudo systemctl start docker
echo "For this Stack, you will use $(ip -f inet addr show enp0s8 | sed -En -e 's/.*inet ([0-9.]+).*/\1/p') IP Address"
  1. Deploiement de regdocker
vagrant up
  1. Ce connecter en ssh
ssh vagrant@<IP_REGISTRY>
  1. Creation d'un reseau "reg-study-net"
docker network create reg-study-net
  1. Creation du conteneur BACKEND
docker run -d -p 5000:5000 -e REGISTRY_STORAGE_DELETE_ENABLED=true --net reg-study-net --name registry-study-net registry:2
  1. Creation du conteneur FRONTEND
docker run -d -p 8090:80 --net reg-study-net -e REGISTRY_URL=http://registry-study-net:5000 -e DELETE_IMAGES=true -e REGISTRY_TITLE=reg-study-net --name frontend-study-net joxit/docker-registry-ui:1.5-static
  1. Verification de l' activitee de nos conteneurs
docker ps
CONTAINER ID   IMAGE                                 COMMAND                  CREATED          STATUS          PORTS                                       NAMES
4104823b1746   joxit/docker-registry-ui:1.5-static   "/docker-entrypoint.…"   9 seconds ago    Up 8 seconds    0.0.0.0:8090->80/tcp, :::8090->80/tcp       frontend-study-net
47d021115527   registry:2                            "/entrypoint.sh /etc…"   27 seconds ago   Up 26 seconds   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   registry-study-net
  1. Connexion a la WEBGUI de notre registry alt text

Lien : Private Registry

13. PULL IMAGE DOCKER HUB TO PUSH PRIVATE REGISTRY

  1. Pull d'une image depuis le Docker-hub
docker pull nginx:latest
  1. Preparation pour tag de notre image
docker images
REPOSITORY                 TAG          IMAGE ID       CREATED        SIZE
nginx                      latest       04661cdce581   18 hours ago   141MB
registry                   2            b2cb11db9d3d   2 months ago   26.2MB
joxit/docker-registry-ui   1.5-static   74416e0cd8ba   8 months ago   24.2MB
  1. Tag de l'image "nginx" dans cette exemple
docker tag <IMAGE ID> localhost:5000/nginx:private-registry
  1. Push image en local depuis notre host
docker push localhost:5000/nginx:private-registry
docker images
REPOSITORY                 TAG                IMAGE ID       CREATED        SIZE
nginx                      latest             04661cdce581   18 hours ago   141MB
localhost:5000/nginx       private-registry   04661cdce581   18 hours ago   141MB
registry                   2                  b2cb11db9d3d   2 months ago   26.2MB
joxit/docker-registry-ui   1.5-static         74416e0cd8ba   8 months ago   24.2MB

  • Details de notre image depuis notre WebGUI: alt text

NB: On remarque que l'on a la possibiliter de supprimer notre image.

14. PUSH D'UNE IMAGE DEPUIS UNE AUTRE MACHINE (DISTANTE) VERS NOTRE PRIVATE REGISTRY

  1. Pull d'une immage par exemple stocker dans notre Docker hub, on va la telecharger vers mpdocker puis l' envoyer vers regdocker (Private Registry)
sudo docker login
sudo docker pull cfreijanes/student-list_api:latest
  1. Depuis notre machine mpdocker on va lister nos images pour voir si on la dans notre referentiel sur notre machine mpdocker of Course !
sudo docker images
REPOSITORY                    TAG              IMAGE ID       CREATED        SIZE  
nginx                         latest           04661cdce581   20 hours ago   141MB 
10.0.0.201:5000/nginx         private-remote   04661cdce581   20 hours ago   141MB 
cfreijanes/student-list_api   latest           e85d03d15757   24 hours ago   1.13GB
  1. On va Tagger l'image de notre API avec la ref
sudo docker tag <IMAGE ID> <IP_REGISTRY>:5000/student-list_api:centos-remote
  1. Dans le cadre de ce mini-projet je vais proposer une solution de contournement pour permettre a notre machine mpdocker de pouvoir pusher notre image par http. :)
sudo vi /usr/lib/systemd/system/docker.service
  • Remplacer <IP_REGISTRY> par l'IP de votre private registry
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --insecure-registry <IP_REGISTRY>:5000
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500
[Install]
WantedBy=multi-user.target
  • Une fois cela fait on va redemarrer le daemon et le service docker
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl status docker
  1. Push de l'image de notre API vers notre private registry (regdocker)
sudo docker push <IP_REGISTRY>:5000/student-list_api:centos-remote
  1. On peut aussi supprimer nos images

alt text

15. CHECK DEPUIS NOTRE WEGUI PRIVATE REGISTRY

Lien : Private Registry

alt text