docker 之cp命令使用,dockercp命令


为了比较详细地描述docker ps 地用法,首先得了解我用来
说明的镜像的dockerfile
如下

➜  openresty git:(master) cat Dockerfile 
FROM harbor.enncloud.cn/qinzhao-harbor/ubuntu-openresty:v1.0.0

ENV PATH /usr/local/openresty/nginx/sbin:$PATH

ADD nginx.conf /work/conf/

WORKDIR /work/

EXPOSE 8080

#CMD ["nginx", "-g", "daemon off;"]

CMD /usr/local/openresty/nginx/sbin/nginx -g 'daemon off;' -c /work/conf/nginx.conf
➜  openresty git:(master) sudo docker images
REPOSITORY                                           TAG                  IMAGE ID            CREATED             SIZE
reg.enncloud.cn/qinzhao-harbor/ubuntu-openresty      v1.0.14              6f086fe82845        46 hours ago        482 MB

以上就是我用来说明的镜像
1. 从 container 到 主机(host)

 docker cp <containerId>:/file/path/within/container /host/path/target

现在我要从镜像v1.0.14所起的容器中cp /work/conf/nginx.conf 文件
docker run

➜  openresty git:(master) sudo docker run -d -p 9090:8080 reg.enncloud.cn/qinzhao-harbor/ubuntu-openresty:v1.0.14
Password:
4bbb4313ac0d9401255dc116d6aa9f381a5bcd04e96a611b7139cc6dfb612d7f
➜  openresty git:(master) ll
total 16
-rw-r--r--  1 xinzhiyun  staff   292B  7 17 23:59 Dockerfile
-rw-r--r--  1 xinzhiyun  staff     0B  7 18 00:08 README.md
-rw-r--r--  1 xinzhiyun  staff   294B  7 17 22:44 nginx.conf
drwxr-xr-x  2 xinzhiyun  staff    68B  7 19 21:39 test
➜  openresty git:(master) ls test 
➜  openresty git:(master) 

docker cp

➜  openresty git:(master) sudo docker cp 4bbb4313ac0d:/work/conf/nginx.conf ./test/
➜  openresty git:(master) ✗ ll test 
total 8
-rw-r--r--  1 root  staff   294B  7 17 22:44 nginx.conf

2. 从 主机(host) 到 container

 ➜  openresty git:(master) ✗ sudo docker exec -it 4bbb4313ac0d sh
# ls
conf  logs
# cd
# pwd
/root
# ls
# 
➜  openresty git:(master) ✗ sudo docker cp test/nginx.conf 4bbb4313ac0d:/root/
Password:
➜  openresty git:(master) ✗ 
➜  openresty git:(master) ✗ sudo docker exec -it 4bbb4313ac0d sh
# pwd
/root
# ls
nginx.conf
# 

之后 你docker commit 就可以保存该容器为新镜像了

相关内容

    暂无相关文章