Stay hungry,Stay foolish

0%

docker-container-commit

基于已有镜像变更

查看已有镜像

1
2
3
4
root@dev:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 219ee5171f80 5 days ago 1.23MB
ubuntu latest f643c72bc252 13 days ago 72.9MB

新起一个container

1
2
3
4
5
6
root@dev:~# docker run -it --name test-ubuntu -d ubuntu
d48bacd8ab10b9a96afba2e1e15ee940029ec1e607a290c47e8fb767f88775cc

root@dev:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d48bacd8ab10 ubuntu "/bin/bash" 47 seconds ago Up 45 seconds test-ubuntu

对container进行些许变更

1
2
3
4
root@dev:~# docker exec -it test-ubuntu bash
root@d48bacd8ab10:/# echo "Hello World!" >> testFile
root@d48bacd8ab10:/# cat testFile
Hello World!

docker diff 查看

1
2
3
4
root@dev:~# docker diff test-ubuntu
C /root
A /root/.bash_history
A /testFile

docker commit 提交和确认

1
2
3
4
5
6
7
8
root@dev:~# docker commit -a 'author@dev.com' -m 'test container commit' test-ubuntu test-images:v1
sha256:1bc4baa7f362781119d0935043e8d433ba6f3263e510f2a8d7660e7fafaa36eb

root@dev:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test-images v1 1bc4baa7f362 5 seconds ago 72.9MB
busybox latest 219ee5171f80 5 days ago 1.23MB
ubuntu latest f643c72bc252 13 days ago 72.9MB

基于test-images镜像新起一个container

1
2
3
4
root@dev:~# docker run -it test-images:v1 bash

root@6ef2a7b10cee:/# cat testFile
Hello World!

可以继续通过docker push推送到docker hub等地方