root@hello:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15db0ba492cf nginx "/docker-entrypoint.…" About a minute ago Up About a minute 0.0.0.0:88->80/tcp, :::88->80/tcp myningx
root@hello:~#
停止容器
root@hello:~# docker stop 15db0ba492cf
15db0ba492cf
root@hello:~#
root@hello:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
root@hello:~#
查看所有容器
root@hello:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15db0ba492cf nginx "/docker-entrypoint.…" 2 minutes ago Exited (0) 12 seconds ago myningx
root@hello:~#
启动容器
root@hello:~# docker start 15db0ba492cf
15db0ba492cf
root@hello:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15db0ba492cf nginx "/docker-entrypoint.…" 2 minutes ago Up 3 seconds 0.0.0.0:88->80/tcp, :::88->80/tcp myningx
root@hello:~#
删除容器,在运行中无法删除
root@hello:~# docker rm 15db0ba492cf
Error response from daemon: You cannot remove a running container 15db0ba492cf2b86714e3e29723d413b97e64cc2ee361d4109f4216b2e0cba60. Stop the container before attempting removal or force remove
root@hello:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e3788cdd7be6 nginx "/docker-entrypoint.…" 4 minutes ago Up 4 minutes 0.0.0.0:88->80/tcp, :::88->80/tcp myningx
root@hello:~#
root@hello:~# docker commit -a "cby" -m "my app" e3788cdd7be6 myapp:v1.0
sha256:07a7b54c914c79dfbd402029a3d144201235eca72a4f26c92e2ec7780c485226
root@hello:~#
root@hello:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myapp v1.0 07a7b54c914c 4 seconds ago 141MB
nginx latest e9ce56a96f8e 8 hours ago 141MB
root@hello:~#
7、镜像保存与导入
root@hello:~# docker save -o cby.tar myapp:v1.0
root@hello:~# ll cby.tar
-rw------- 1 root root 145910784 Nov 17 02:21 cby.tar
root@hello:~#
root@hello:~# docker load -i cby.tar
Loaded image: myapp:v1.0
root@hello:~#
root@hello:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myapp v1.0 07a7b54c914c 3 minutes ago 141MB
nginx latest e9ce56a96f8e 8 hours ago 141MB
nginx 1.20.1 c8d03f6b8b91 5 weeks ago 133MB
root@hello:~#
8、推送到DockerHub,并在其他主机上可拉去该镜像
root@hello:~# docker tag myapp:v1.0 chenbuyun/myapp:v1.0
root@hello:~#
root@hello:~# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: chenbuyun
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
root@hello:~# docker push chenbuyun/myapp:v1.0
The push refers to repository [docker.io/chenbuyun/myapp]
799aefeaf6b1: Pushed
fd688ba2259e: Mounted from library/nginx
c731fe3d8126: Mounted from library/nginx
3b1690d8cd86: Mounted from library/nginx
03f105433dc8: Mounted from library/nginx
bd7b2912e0ab: Mounted from library/nginx
e8b689711f21: Mounted from library/nginx
v1.0: digest: sha256:f085a533e36cccd27a21fe4de7c87f652fe9346e1ed86e3d82856d5d4434c0a0 size: 1777
root@hello:~#
root@hello:~# docker logout
Removing login credentials for https://index.docker.io/v1/
root@hello:~#
root@hello:~# docker pull chenbuyun/myapp:v1.0
v1.0: Pulling from chenbuyun/myapp
Digest: sha256:f085a533e36cccd27a21fe4de7c87f652fe9346e1ed86e3d82856d5d4434c0a0
Status: Downloaded newer image for chenbuyun/myapp:v1.0
docker.io/chenbuyun/myapp:v1.0
root@hello:~#
root@hello:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
chenbuyun/myapp v1.0 07a7b54c914c 9 minutes ago 141MB
myapp v1.0 07a7b54c914c 9 minutes ago 141MB
nginx latest e9ce56a96f8e 8 hours ago 141MB
nginx 1.20.1 c8d03f6b8b91 5 weeks ago 133MB
root@hello:~#