why
Docker イメージ 管理コマンドの続き
コンテナとは
- Dockerfile から イメージを作成
- または docker hub から pull してくる
- イメージからコンテナを作成
- コンテナを使って Docker 環境の中で サーバーなどを立てる
- Ubuntu bash, npm next run dev, mysql start, など
Container images become containers at runtime and in the case of Docker containers - images become containers when they run on Docker Engine.
- コンテナイメージが Docker エンジンで走るときにコンテナになる...
- イメージがそもそもコンテナイメージのことだった
Available for both Linux and Windows-based applications, containerized software will always run the same, regardless of the infrastructure. Containers isolate software from its environment and ensure that it works uniformly despite differences for instance between development and staging.
- Linux と Windows で走る
- dev でも stg でも環境から独立してる
run, 動かす
- 自明。ないと dockerhub から latest を pull してくれる
restart, 止まっているコンテナの再起動
- ctrl c とかで止めていたコンテナを再開する
- これをしておかないと exce しても動かない?
exec, 動いている?コンテナの実行
- 一回 exit した ubutu bash イメージをもう一度使うやつ
rm, コンテナの削除
Remove one or more containers
docker rm [OPTIONS] CONTAINER [CONTAINER...]
Remove a container
This removes the container referenced under the link /redis.
$ docker rm /redis
/redis
-
/redis
?/
ルートがいるのか?と思ってみてみると
b0f5288f6eab hello-world "/hello" 2 months ago Exited (0) 2 months ago
- 公式の
hello-world
イメージは ルートマークがついていた - 公式から引っ張ってきたイメージは付くってことだろうか
prune, 使わないものを削除
docker container prune [OPTIONS]
Removes all stopped containers.
Name, shorthand Default Description
--filter Provide filter values (e.g. ‘until=')
--force , -f Do not prompt for confirmation
- filter したり確認をスキップしたりできる
docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
bb685991dc911c67909dbe6ba9e7654ad12171758042e478a6731d329f88317c
fbb35a34304c748b55d63b4e0c0fd27ee9323abb24fb441b4d832411fc7c4766
eab143705b1536b45fc0e0edf7be56e7f9a868b24170a446eb3654f49023cc62
~
305ed23af520111323f6995273805e63b130ee61bd5663327dc9b93abb664504
Total reclaimed space: 647.4kB
ある程度は削除できた
コンテナを再表示してみると
docker container ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e10186ce617d mysql:5.7 "docker-entrypoint.s…" 24 hours ago Up 24 hours 3306/tcp, 33060/tcp nextjs-blog_db_run_1d4cc30c296c
a4da8e1bbf71 mysql:5.7 "docker-entrypoint.s…" 25 hours ago Up 25 hours 3306/tcp, 33060/tcp nextjs-blog_db_1
10075622af77 ubuntu "bash" 2 days ago Up 39 hours elegant_euler
99529632c371 kaede0902/docker-nextjs:latest "docker-entrypoint.s…" 6 days ago Up 6 days 0.0.0.0:3333->3000/tcp inspiring_gagarin
- やった!!!!!最小限になってる!!!!プルーン最高!!!!
stop, 動いてるコンテナプロセスを止める
kill と同じ?
docker ps -q | xargs docker stop
- これをすると全て止められる
docker ps -q | xargs docker stop
94671198d634
fd39a76e9b60
48152c3af5c2
e10186ce617d
a4da8e1bbf71
10075622af77
99529632c371
RYOs-MBP:code kaede$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
243feeafe4f5 adminer:latest "entrypoint.sh docke…" 14 seconds ago Up 9 seconds 8080/tcp postgres_adminer.1.tfm61wkfsqwx4nn3xvbb8vytt
e9bf9d343013 postgres:latest "docker-entrypoint.s…" 15 seconds ago Up 9 seconds 5432/tcp postgres_db.1.e9yoaljz72mpgz6uixevbz41
- stack deploy で動かしているものは止まらない?
- 動いてるものを止めることは必要だと思うが、記事にあるようにコンテナの削除まで普段する必要があるのか?
kill $(docker ps -q)
- kill id と プロセスのリストをまとめてるので kill all 相当
- 実際すごい