标签:exe host mes home 进入 and 文件 exit att
进入当前正在运行的容器: #我们通常容器都是后台运行的,需要进入容器,修改一些配置
#方式1: docker exec -it 容器id /bin/bash #进入容器后开启一个新的终端,可以在里面操作【常用】 #方式2: docker attach 容器id #进入容器正在执行的终端,不会启动新的线程
复制文件:
docker cp 容器id:/文件所在容器目录/文件名 /目标目录
#进入docker容器内部
[root@localhost gsl]# docker attach d03a1d206464
[root@d03a1d206464 /]# cd /home
bash: $‘cd\343‘: command not found
[root@d03a1d206464 /]# cd home
[root@d03a1d206464 home]# ls
#在容器内创建一个文件
[root@d03a1d206464 home]# touch test.java
[root@d03a1d206464 home]# ls
test.java
[root@d03a1d206464 home]# exit
exit
[root@localhost gsl]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost gsl]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e7d2c5417147 centos "/bin/sh -c ‘while t…" 36 minutes ago Exited (137) About a minute ago serene_khorana
d03a1d206464 centos "/bin/bash" 45 minutes ago Exited (0) 19 seconds ago quizzical_shtern
5d5dec77f40a centos "/bin/bash" 48 minutes ago Exited (0) 48 minutes ago hopeful_liskov
8ee4effed193 centos "/bin/bash" 50 minutes ago Exited (0) 50 minutes ago epic_hertz
f3504e169f27 centos "/bin/bash" 52 minutes ago Exited (0) 52 minutes ago cool_cerf
01913d634873 centos "/bin/bash" 59 minutes ago Exited (0) 58 minutes ago nostalgic_morse
8f87f9b89d52 centos "/bin/bash" About an hour ago Exited (0) 51 minutes ago frosty_noyce
#将这个容器中的文件拷贝到外面的主机上
[root@localhost gsl]# docker cp d03a1d206464:/home/test.java /home
[root@localhost gsl]# ls
omnetpp-5.6.1 omnetpp-5.6.1-src-linux.tgz qt-opensource-linux-x64-5.9.9.run redis-2.8.17 redis-2.8.17.tar.gz
[root@localhost gsl]# cd home
bash: cd: home: 没有那个文件或目录
[root@localhost gsl]# cd /home
[root@localhost home]# ls
gsl test.java
标签:exe host mes home 进入 and 文件 exit att
原文地址:https://www.cnblogs.com/gslgb/p/14614256.html