如何复制文件到docker容器中(实操)
短信预约 -IT技能 免费直播动态提醒
步骤一:查看docker镜像
命令 docker images 锁定容器tomcat
[root@ecs- ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEhub.cloudx5.com/justep/gateway-init 1.0 3d26e9ba2df0 2 years ago 92.1MBhub.cloudx5.com/justep/dbrest 1.0.1 780b3ae16949 2 years ago 106MBhub.cloudx5.com/justep/adminer 1.0 a16d1fd76db4 2 years ago 145MBcertbot/certbot latest 994e18b9d74d 2 years ago 92.2MB c99efc745e9b 3 years ago 92.1MBhub.cloudx5.com/justep/database-init 1.0 2fe4f106e3ac 3 years ago 141MB 886d8c169d03 3 years ago 145MBhub.cloudx5.com/justep/kong 0.11.2 6c215f862793 3 years ago 147MBhub.cloudx5.com/justep/minio 1.0.2 7e4ae5d3ea35 3 years ago 281MB 6d131f0b7034 3 years ago 104MBhub.cloudx5.com/justep/tomcat 8 f550faa880e8 3 years ago 111MBhub.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 tomcatdd43969828b5 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-chuangzhidaodd43969828b5450ec6d45e070ae82ba4c31daae8a9c2533e0495892aa137d835
步骤四:拷贝文件到容器指定位置
命令 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/bashbash-4.4# lsBUILDING.txt NOTICE RUNNING.txt include native-jni-lib workCONTRIBUTING.md README.md bin lib tempLICENSE RELEASE-NOTES conf logs webappsbash-4.4# cd /bash-4.4# ls2c3e75497b243b157bb55b96ec06e145.txt data etc media root srv tmp workUsers dev home mnt run store usrbin dist lib proc sbin sys varbash-4.4#
来源地址:https://blog.csdn.net/weixin_42517271/article/details/129632749
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341