Écrivez les paramètres que vous ne voulez pas réécrire dans / etc / docker / daemon.json
au lieu de docker.service
.
Lorsque j'exécutais yum update avec cron, l'image Docker était complètement claire après une journée de mise à jour.
La cause était que la racine lorsque le démon Docker était en cours d'exécution était réécrite dans le fichier de service.
Au moment de la mise à jour de yum, docker.service
a été remplacé par le paramètre par défaut de la nouvelle version, et la racine à l'exécution est revenue à la valeur par défaut ( / var / lib / docker
).
Il est censé être après yum remove docker-ce
sur la machine qui avait à l'origine docker-ce.
Vous pouvez vérifier la version précédente avec la commande suivante.
# yum list --showduplicates | grep docker-ce.x86_64
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
(Ce qui suit est omis)
Si l'architecture n'est pas x86_64
, veuillez lire comme il convient. Installez avec 19.03.10
selon le cas. (Tout va bien si ce n'est pas le dernier.)
# yum install -y docker-ce-19.03.10-3.el7
docker.service
Le fichier original est le suivant. Comme il est long, je vais extraire uniquement la partie [Service] que je prévois de réécrire.
[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 -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
Remplacez ceci par: Créez / opt / docker
à l'avance.
[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 -H fd:// --graph /opt/docker --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
Exécutez hello-world
et vérifiez que l'image est sous / opt / docker
.
# systemctl start docker
# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
(réduction)
# ll /opt/docker
total 0
drwx------. 2 root root 24 Nov 2 04:46 builder
drwx--x--x. 4 root root 92 Nov 2 04:46 buildkit
drwx------. 3 root root 78 Nov 2 04:46 containers
drwx------. 3 root root 22 Nov 2 04:46 image
drwxr-x---. 3 root root 19 Nov 2 04:46 network
drwx------. 6 root root 261 Nov 2 04:46 overlay2
drwx------. 4 root root 32 Nov 2 04:46 plugins
drwx------. 2 root root 6 Nov 2 04:46 runtimes
drwx------. 2 root root 6 Nov 2 04:46 swarm
drwx------. 2 root root 6 Nov 2 04:46 tmp
drwx------. 2 root root 6 Nov 2 04:46 trust
drwx------. 2 root root 25 Nov 2 04:46 volumes
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 10 months ago 13.3kB
C'est bon.
Il sera mis à jour au dernier "19.03.13" à partir du 02/11/2020.
# yum update -y docker-ce
# docker --version
Docker version 19.03.13, build 4484c46d9d
Vérifiez le fichier de service. (Extrait de [Service] uniquement)
# cat /usr/lib/systemd/system/docker.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 -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
Le --graph = / opt / docker
que vous auriez dû définir plus tôt a disparu.
La liste d'images est vide même si le fichier d'origine reste dans / opt / docker
comme indiqué ci-dessous.
# ll /opt/docker/
total 0
drwx------. 2 root root 24 Nov 2 04:46 builder
drwx--x--x. 4 root root 92 Nov 2 04:46 buildkit
drwx------. 3 root root 78 Nov 2 04:46 containers
drwx------. 3 root root 22 Nov 2 04:46 image
drwxr-x---. 3 root root 19 Nov 2 04:46 network
drwx------. 6 root root 261 Nov 2 04:46 overlay2
drwx------. 4 root root 32 Nov 2 04:46 plugins
drwx------. 2 root root 6 Nov 2 04:46 runtimes
drwx------. 2 root root 6 Nov 2 04:46 swarm
drwx------. 2 root root 6 Nov 2 04:46 tmp
drwx------. 2 root root 6 Nov 2 04:46 trust
drwx------. 2 root root 25 Nov 2 04:46 volumes
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Utilisez / etc / docker / daemon.json
.
Le contenu de ʻexecStart de
docker.service` qui est entré par défaut est le suivant
/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Les valeurs par défaut sont utilisées pour toutes les options sauf celles définies ici. Consultez les options qui peuvent être pertinentes sur la base du Guide officiel.
option | Valeur par défaut | Explication |
---|---|---|
-g, --graph | /var/lib/docker | Docker root lors de l'exécution de Docker |
--config-file | /etc/docker/daemon.json | Fichier de configuration du démon |
Puisque --graph
n'est pas spécifié dans le fichier de service qui est entré au moment de la mise à jour, il retournera à / var / lib / docker
quoi qu'il arrive. Vous pouvez donc éditer / etc / docker / daemon.json
, qui est spécifié par défaut comme --config-file
.
C'est un fichier qui n'existe pas lorsque Docker est installé, alors créez-en un nouveau.
Modifiez le fichier afin qu'il ait le contenu suivant.
# cat /etc/docker/daemon.json
{
"graph": "/opt/docker"
}
Désinstallez docker-ce une fois et réessayez la mise à jour. Pour confirmation, supprimez le contenu de l'itinéraire lors de l'exécution de Docker.
# yum remove docker-ce
# rm -rf /var/lib/docker/*
# rm -rf /opt/docker/*
・ Installation des versions antérieures
# yum -y yum install -y docker-ce-19.03.10-3.el7
# systemctl stard docker
・ Vérifiez le fichier de réglage
# cat /usr/lib/systemd/system/docker.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 -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
# cat /etc/docker/daemon.json
{
"graph": "/opt/docker"
}
・ Exécution Hello-world
# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
(Omis ci-dessous)
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 10 months ago 13.3kB
# ll /opt/docker/
total 0
drwx------. 2 root root 24 Nov 2 05:14 builder
drwx--x--x. 4 root root 92 Nov 2 05:14 buildkit
drwx------. 3 root root 78 Nov 2 05:14 containers
drwx------. 3 root root 22 Nov 2 05:14 image
drwxr-x---. 3 root root 19 Nov 2 05:14 network
drwx------. 6 root root 261 Nov 2 05:14 overlay2
drwx------. 4 root root 32 Nov 2 05:14 plugins
drwx------. 2 root root 6 Nov 2 05:14 runtimes
drwx------. 2 root root 6 Nov 2 05:14 swarm
drwx------. 2 root root 6 Nov 2 05:14 tmp
drwx------. 2 root root 6 Nov 2 05:14 trust
drwx------. 2 root root 25 Nov 2 05:14 volumes
・ Exécuter la mise à jour de yum
# yum -y update docker-ce
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 10 months ago 13.3kB
Vous pouvez maintenant mettre à jour Docker avec cron!
daemon.json
devrait probablement couvrir tout ce qui peut être défini dans le fichier de service ʻexecStart. Mettons à jour
daemon.json sans toucher
docker.service`.
Au fait, je n'ai pas remarqué cela pendant un certain temps et je l'ai laissé dans le post-traitement de la mise à jour de yum de cron. Arrêtons de pousser comme ça. (Autodiscipline)