Před pár dny bylo rozhodnuto na jednom ze serverů přesunout docker storage (adresář, kde docker uchovává všechny soubory kontejnerů a obrazů) na samostatnou partici, která
měla větší kapacitu. Úkol se zdál být triviální a nic nenaznačovalo problémy...
Začínáme:
1. Zastavujeme a zabíjíme všechny kontejnery naší aplikace:
docker-compose downPokud je více kontejnerů a jsou v různých compose, můžeme použít takto:
docker rm -f $(docker ps -q)2. Zastavujeme docker démon:
systemctl stop docker3. Přesouváme adresář na požadované místo:
cp -r /var/lib/docker /docker/data/storage4. Říkáme docker démonovi, aby se díval do nového adresáře. Zde je několik možností: buď přes flag -g specifikovat novou cestu pro démona, nebo použít systemd konfigurace, které jsme taktéž použili. Nebo symbolický odkaz. Nechci to podrobně rozepisovat, na internetu manuálů o přenosu docker root na nové místo.
5. Spouštíme docker démona a kontrolujeme, zda se dívá tam, kam má:
systemctl status dockerV jednom z výstupních řádků bychom měli vidět:
├─19493 /usr/bin/dockerd --data-root=/docker/data/storageUjistili jsme se, že jsme démona informovali o volbě, teď zkontrolujeme, zda ji aplikoval (děkuji )!
docker info | awk '/Root Dir/ {print $NF}' 6. Spouštíme naši aplikaci:
docker-compose up -d7. Kontrolujeme
A tady začíná to nejzajímavější, DB, MQ, všechno v pořádku! Databáze je celá, všechno funguje… kromě nginx. Máme vlastní sestavení nginx s Kerberos a kurtizánami. A prohlížení logů kontejneru ukázalo, že nemůže zapisovat do /var/tmp — Permission denied. Masíruji si spánky a snažím se analyzovat situaci… Jak je to možné? Docker obraz se přece nezměnil. My jsme jen přenesli adresář. Vždy to fungovalo, a teď tohle… Pro experiment jsem ručně vstoupil do kontejneru a změnil práva na tento adresář, bylo tam root, root 755, dal root, root 777. A všechno se rozjelo… V hlavě se mi ozval myšlenka — to je nějaký nesmysl… Myslel jsem si, že jsem něco přehlédl…
Rozhodl jsem se, že jsme při přesunu ztratili práva na soubory. Zastavili jsme aplikaci, docker démon, smazali novou adresář a provedli kopírování adresáře /var/lib/docker již s použitím rsync -a.
Myslím, že teď by to mělo být v pořádku, zvedáme docker, aplikaci.
Aah… the problem still persists… My eye started twitching. I rushed to the console of my virtual machine where I run various tests; I had this nginx image, and I got inside the container, and here the permissions on the /var/tmp directory are set to root, root 777. That is, the same permissions I had to set manually. But the images are identical!
The xfs filesystem was used everywhere.
I compared using the command
docker inspect my-nginx:12345All hashes are identical, exactly the same. On the server, as well as 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 remains… Now my other eye is twitching.
I can't remember what thoughts were in my head besides screams of 'AAAAA' and the like. It's 4 AM outside, and I started going through the Docker source code to understand the hashing principle of image layers. I opened my third energy drink. And in the end, I realized that hashing only takes into account the file and its contents, but NO ACCESS RIGHTS! So, for some mysterious reason, our permissions got messed up, even though SELinux is disabled, ACLs are not used, and there is 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 when transferring, permissions got messed up, both inside the local image and inside the image in the registry. As I mentioned, for various reasons, it was located on the same machine. And consequently in the /var/lib/docker directory.
And anticipating the question, whether we tried to redirect Docker to the old directory — no, we didn't try, unfortunately, circumstances did not allow. But I really wanted to figure it out.
After writing this article, the solution seems obvious to me, but at the time it didn't seem so. I honestly googled and didn't find similar situations.
In conclusion: I solved the problem, but I still don't understand the reason =(
If anyone has any ideas or possible reasons for this problem — I would be extremely grateful for your comments!
Zdroj: habr.com
