docker image 迁移

要迁移 docker image 有三个方法

1.拿到 docker repo, Dockerfile 重新 build

docker build .

2.通过 docker registry

 docker pull image


保存一个 tar 文件

docker save -o  


docker load -i 


运行一个 centos 容器
The -i and -t flags can be passed to the exec command to keep an interactive shell open, and you can specify the shell you want to attach after the container ID.

[root@localhost ~]# docker run  -i -t centos /bin/bash
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
8d30e94188e7: Pull complete 
Digest: sha256:2ae0d2c881c7123870114fb9cc7afabd1e31f9888dac8286884f6cf59373ed9b
Status: Downloaded newer image for centos:latest

运行 docker 以 daemon 方式运行,host 开放端口 5001,对应容器内端口 5000
The -p means “publish ports”

docker run -d -p 5001:5000 python-flask


docker info
Containers: 1
 Running: 0
 Paused: 0
 Stopped: 1
Images: 1


docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
ebf5f9bf4bc9        centos              "/bin/bash"         16 minutes ago      Exited (0) 7 minutes ago                       furious_leakey

查看 docker 运行的 log

docker logs  furious_leakey

探测 docker 更详尽信息,json 输出

docker inspect furious_leakey

退出后的容器是 stopped 状态,现在根据名字 furious_leakey 启动它

docker start furious_leakey

通过 shell 进入到容器中

docker attach furious_leakey






删除所有 docker 容器

docker rm `docker ps -a -q`

进入到运行中的 docker

docker exec -i -t 82d98bdf2d77046ce52a61f2bab27465db868a97faebe94a83581fc0322e4c26 /bin/bash