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 downako 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 docker3. PremjeŔtamo direktorij na željeno mjesto:
cp -r /var/lib/docker /docker/data/storage4. 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 dosta vodiÄa o premjeÅ”tanju Docker root u novo mjesto.
5. PokreÄemo Docker demona i pratimo da gleda gdje treba:
systemctl status dockerU jednom od redova izlaza trebali bismo vidjeti:
āā19493 /usr/bin/dockerd --data-root=/docker/data/storageProvjerili smo da je opcija proslijeÄena demonu, sada Äemo provjeriti je li je primijenio (hvala )!
docker info | awk '/Root Dir/ {print $NF}' 6. PokreÄemo naÅ”u aplikaciju:
docker-compose up -d7. 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:12345All 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
