如何复制文件到docker容器中(实操)
如何复制文件到docker容器中(实操)
·
步骤一:查看docker镜像
命令 docker images 锁定容器tomcat
[root@ecs- ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hub.cloudx5.com/justep/gateway-init 1.0 3d26e9ba2df0 2 years ago 92.1MB
hub.cloudx5.com/justep/dbrest 1.0.1 780b3ae16949 2 years ago 106MB
hub.cloudx5.com/justep/adminer 1.0 a16d1fd76db4 2 years ago 145MB
certbot/certbot latest 994e18b9d74d 2 years ago 92.2MB
<none> <none> c99efc745e9b 3 years ago 92.1MB
hub.cloudx5.com/justep/database-init 1.0 2fe4f106e3ac 3 years ago 141MB
<none> <none> 886d8c169d03 3 years ago 145MB
hub.cloudx5.com/justep/kong 0.11.2 6c215f862793 3 years ago 147MB
hub.cloudx5.com/justep/minio 1.0.2 7e4ae5d3ea35 3 years ago 281MB
<none> <none> 6d131f0b7034 3 years ago 104MB
hub.cloudx5.com/justep/tomcat 8 f550faa880e8 3 years ago 111MB
hub.cloudx5.com/justep/java 8-jre 58445151ac69 3 years ago 90.4MB
步骤二:查找容器确定容器名
命令 docker ps -a 或者直接找对应的 docker ps -a | grep tomcat 查看最后一个属性 names 我这里是tomcat-chuangzhidao
[root@ecs-chuangzd ~]# docker ps -a | grep tomcat
dd43969828b5 hub.cloudx5.com/tomcat:8 "/usr/local/bin/dock…" 18 hours ago Up 14 hours 8080/tcp tomcat-chuangzhidao
步骤三:根据容器名获取容器长ID
命令 docker inspect -f '{{.ID}}' 容器名
[root@ecs-chuangzd ~]# docker inspect -f '{{.ID}}' tomcat-chuangzhidao
dd43969828b5450ec6d45e070ae82ba4c31daae8a9c2533e0495892aa137d835
步骤四:拷贝文件到容器指定位置
命令 docker cp 文件 长ID:目录,这里我从根目录上传至容器根目录
[root@ecs-chuangzd ~]# docker cp /2c3e75497b243b157bb55b96ec06e145.txt dd43969828b5450ec6d45e070ae82ba4c31daae8a9c2533e0495892aa137d835:/
步骤四:进容器查看操作
命令 docker exec -it 【 CONTAINER ID】 /bin/bash
CONTAINER ID就是docker ps -a 第一个属性名 我这里是dd43969828b5
[root@ecs-chuangzd ~]# docker exec -it dd43969828b5 /bin/bash
bash-4.4# ls
BUILDING.txt NOTICE RUNNING.txt include native-jni-lib work
CONTRIBUTING.md README.md bin lib temp
LICENSE RELEASE-NOTES conf logs webapps
bash-4.4# cd /
bash-4.4# ls
2c3e75497b243b157bb55b96ec06e145.txt data etc media root srv tmp work
Users dev home mnt run store usr
bin dist lib proc sbin sys var
bash-4.4#
更多推荐
已为社区贡献1条内容
所有评论(0)