Istorija problema sa prenosom docker storage-a (docker root)

Prije nekoliko dana odlučeno je da se docker storage (direktorij u kojem Docker pohranjuje sve datoteke kontejnera i slika) premjesti na posebnu particiju koja
ima veći kapacitet. Zadatak se činio trivijalnim i nije nagovjeÅ”tavao probleme…

Krećemo:

1. Zaustavljamo i ubijamo sve kontejneri naŔe aplikacije:

docker-compose down

ako ima mnogo kontejnera i nalaze se u različitim compose datotekama, možemo to učiniti ovako:

docker rm -f $(docker ps -q)

2. Zaustavljamo Docker demon:

systemctl stop docker

3. PremjeŔtamo direktorij na željeno mjesto:

cp -r /var/lib/docker /docker/data/storage

4. ObavjeÅ”tavamo Docker demona da gleda u novi direktorij. Ima nekoliko opcija: ili preko -g opcije navesti novog putanju, ili kroz systemd konfiguracije koje smo koristili. Ili simbolički link. Neću previÅ”e objaÅ”njavati, na internetu ima dosta vodiča o premjeÅ”tanju Docker root u novo mjesto.

5. Pokrećemo Docker demona i pratimo da gleda gdje treba:

systemctl status docker

U jednom od redova izlaza trebali bismo vidjeti:

ā”œā”€19493 /usr/bin/dockerd --data-root=/docker/data/storage

Provjerili smo da je opcija proslijeđena demonu, sada ćemo provjeriti je li je primijenio (hvala inkvizitor68sl)!

docker info | awk '/Root Dir/ {print $NF}' 

6. Pokrećemo naÅ”u aplikaciju:

docker-compose up -d

7. Provjeravamo

I tu počinje najzanimljiviji dio, SDB, MQ, sve je u redu! Baza je netaknuta, sve radi… osim nginx-a. Imamo vlastitu verziju nginx-a sa Kerberosom i kuplerajem. I pregled logova kontejnera pokazao je da ne može pisati u /var/tmp — Permission denied. Istežem prste i pokuÅ”avam analizirati situaciju… Kako to? Docker slika se nije promijenila. Samo smo premjestili direktorij. Uvijek je funkcioniralo, a sad… Iz znatiželje sam uÅ”ao u kontejner i promijenio dozvole na ovom direktoriju, bile su root, root 755, dao root, root 777. I sve je proradilo… U glavi mi se pojavila misao — besmisleno… Mislio sam, možda sam neÅ”to propustio…

Odlučio sam da smo izgubili dozvole pristupa datotekama prilikom premjeÅ”tanja. Zaustavili smo aplikaciju, Docker demona, obrisali novu direktorij i izvrÅ”ili kopiranje direktorija /var/lib/docker koristeći rsync -a.

Mislim, sada je sigurno sve u redu, podižemo Docker, aplikaciju.

Iii... the problem remains... My eye twitched. I rushed to the console of my virtual machine where I run various tests; I had this nginx image, and I went into the container, and here in the directory /var/tmp, the permissions are set to root, root 777. That is, the same as what I had to set manually. But the images are identical!

The file system xfs was used everywhere.

I compared using the command

docker inspect my-nginx:12345

All hashes are identical, exactly the same. On the server and on my virtual machine. I deleted the local nginx image and pulled it again from the registry, which for various reasons is on the same machine. And the problem is the same... Now my other eye twitched.

I already don't remember what thoughts were in my head, apart from screams of "AAAAAA" and the like. It's 4 AM outside, I started going through the Docker sources to understand the hashing principle of image layers. I opened the third can of energy drink. And in the end, it dawned on me that hashing only considers the file, its content, but NO ACCESS RIGHTS! So, somehow mysteriously, our permissions got corrupted, and selinux is disabled, acl is not used, there's no sticky bit.

I deleted the local image, also deleted the image from the docker registry, and pushed it again. And everything worked. It turns out that during the transfer, the permissions got corrupted, both inside the local image and in the image located in the registry. As I said, for various reasons, it was on the same machine. And as a consequence in one directory /var/lib/docker.

And anticipating the question of whether I tried to redirect Docker to the old directory — no, I didn't, unfortunately, circumstances didn't allow. And I really wanted to figure it out.

After writing this article, the solution to the problem seems obvious to me, but at the time of investigation it did not seem so. I honestly googled, and found no similar situations.

In the end: I resolved the problem, but I still don't understand the cause =(

If anyone knows or has an idea about possible reasons for this problem — I would be extremely grateful to you in the comments!

Izvor: habr.com

Kupite pouzdan hosting za sajtove uz zaÅ”titu od DDoS, VPS VDS servere šŸ”„ Kupite pouzdan hosting za sajtove uz zaÅ”titu od DDoS, VPS VDS servere | ProHoster