Docker client가 Docker daemon 통신 시 소켓이 docker.sock파일에 정보 작성
Docker daemon은 daemon.json 파일에서
containerd가 런타임의 역할을 함
containerd에게 만들라고하면 자식 프로세스 shim을 만든다. (container/shim, 컨테이너를 2개만들면 shim도 2개)
containerd가 shim을 통해 전달하고, 로그 및 전달사항을 shim이 모니터링
shim은 컨테이너를 만들기 위해 runc를 호출하고, runc는 namespace, cgroup을 접속해 컨테이너에게 필요한 namespace, cgroup을 만들어줌. 만들어지고나서 runc는 종료되고, 컨테이너는 shim과 통신하게 된다.
cd
mkdir 0824 ; cd 0824
sudo apt -y install pip
sudo apt -y install pip
pip install docker
rapa@manager:~/0824$ which python3
/usr/bin/python3
touch ctn.py
vi ctn.py
#!/usr/bin/python3
import docker
client=docker.from_env()
print(client.containers.run("alpine", ["echo","hello","all"]))
docker.from_env() : 도커에 접속해 명령 전달할 수 있는 client 생성
alpine이미지를 다운받아, 컨테이너에는 echo hello all 명령어 전달해서 출력
도커 로그인
권한 조정
chmod +x ctn.py
rapa@manager:~/0824$ ./ctn.py
b'hello all\n'
docker container ls
rapa@manager:~/0824$ docker container ls --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
78fdf2332a70 alpine "echo hello all" 20 seconds ago Exited (0) 19 seconds ago epic_torvalds
cp ctn.py ctn1.py
vi ctn1.py
#!/usr/bin/python3
import docker
client=docker.from_env()
test = client.containers.run("nginx", detach=True)
print(test.id)
이미지는 nginx, detach=True는 -d로 하겠다는 뜻
rapa@manager:~/0824$ ./ctn1.py
5d5f6bb467cc23993785fc6ae015f115439413f67a2e4670c6547832b1a11c66
rapa@manager:~/0824$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5d5f6bb467cc nginx "/docker-entrypoint.…" 41 seconds ago Up 39 seconds 80/tcp flamboyant_colden
rapa@manager:~/0824$ ./ctn1.py
691bbc2b15e7540244471757ce1e39c6662294ffb4e0e034a9dac6bc6913e85e
rapa@manager:~/0824$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
691bbc2b15e7 nginx "/docker-entrypoint.…" 4 seconds ago Up 3 seconds 80/tcp great_buck
5d5f6bb467cc nginx "/docker-entrypoint.…" About a minute ago Up About a minute 80/tcp flamboyant_colden
apa@manager:~/0824$ cp ctn1.py ctn2.py
#!/usr/bin/python3
import docker
client=docker.from_env()
for ctn in client.containers.list():
print(ctn.id)
#!/usr/bin/python3
import docker
client=docker.from_env()
for img in client.images.list():
print(img.id)
rapa@manager:~/0824$ ./ctn2.py
691bbc2b15e7540244471757ce1e39c6662294ffb4e0e034a9dac6bc6913e85e
5d5f6bb467cc23993785fc6ae015f115439413f67a2e4670c6547832b1a11c66
apa@manager:~/0824$ ./ctn2.py
sha256:d0c8ccfcc9a659ebdbcf0c9c32ecafc695b7d827fcfb9a3a95094bcf43c5e11c
sha256:4c291ee6ca0fbcb6ce9f130a79d5ebc4f602467e9cb2bc32e69a289b57759b60
sha256:f13c380e5c65274b13ced2752bf24104ceeefb41f3e8b6c2bd4f65fc0fb7b23e
sha256:7553b2134b08aa366639be615657a3d56bc5981bd2bca8e16ee1e9dd1391442f
sha256:8b4934d093c20fc224afcd45a8d6c4209ce868a69206e22087ddd79932f2e090
sha256:034a5058bebba7f3583c5aa61cb284e95fa427d6003e0703f77d2634136c6296
sha256:5b718f70ccb6fc398a391c5069e50275cacd46b355eeacaaf219484f3591b40f
sha256:e31708f56e9868fcf7d638bd5a3e2689e7de6117cfdf5dc57dee1e19bb3ef61e
sha256:ea572112d3ff9b1446d04d47c3a2b3d8a5283594d8e518656df7cad93fecf5a5
sha256:3a0f7b0a13ef62e85d770396e1868bf919f4747743ece4f233895a246c436394
sha256:9c6f0724472873bb50a2ae67a9e7adcb57673a183cea8b06eb778dca859181b5
sha256:66b89e8b083b68f0bc8c80a4190bc16a72368a1b44e04b1ed625d954a854c9ea
sha256:b692a91e4e1582db97076184dae0b2f4a7a86b68c4fe6f91affa50ae06369bf5
sha256:f2a976f932ec6fe48978c1cdde2c8217a497b1f080c80e49049e02757302cf74
sha256:8d5df41c547bd107c14368ad302efc46760940ae188df451cabc23e10f7f161b
sha256:3147495b3a5ce957dee2319099a8808c1418e0b0a2c82c9b2396c5fb4b688509
sha256:eeb6ee3f44bd0b5103bb561b4c16bcb82328cfe5809ab675bb17ab3a16c517c9
sha256:eb12107075737019dce2d795dd82f5a72197eb3c64b2140392eaad3ba3b8a34e
sha256:0db5683824d8669ef8494f6e2c3aebf29facbda82a07f17e76bc60e752287144