docker 之cp命令使用

来源:互联网 发布:手机淘宝购物 编辑:程序博客网 时间:2024/05/21 17:59

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

➜  openresty git:(master) cat Dockerfile FROM harbor.enncloud.cn/qinzhao-harbor/ubuntu-openresty:v1.0.0ENV PATH /usr/local/openresty/nginx/sbin:$PATHADD 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 imagesREPOSITORY                                           TAG                  IMAGE ID            CREATED             SIZEreg.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.14Password:4bbb4313ac0d9401255dc116d6aa9f381a5bcd04e96a611b7139cc6dfb612d7f
➜  openresty git:(master) lltotal 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.confdrwxr-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# lsconf  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# lsnginx.conf# 

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

原创粉丝点击