最近工作需要用到docker,那就简单写个笔记到时候可以查阅使用。
参考菜鸟教程:https://www.runoob.com/docker/docker-hello-world.html
运行
docker -id 可以后台启动容器,可以通过docker exec -it 容器id /bin/bash 进入交互界面,这样的启动方式。退出的话,容器不会退出。
shijianzhongdeMacBook-Pro:~ shijianzhong$ docker exec -it dab2 /bin/bash [root@dab2da3d3404 /]# exit exit shijianzhongdeMacBook-Pro:~ shijianzhong$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dab2da3d3404 centos "/bin/bash" 4 minutes ago Up 4 minutes dreamy_engelbart shijianzhongdeMacBook-Pro:~ shijianzhong$
也可以通过docker -itd后台运行镜像,这样的话可以通过attach连接后台的运行容器,或者通过docker exec -it 容器id 进入交互界面,但通过exit退出的话,
运行的容器也会退出
docker exec:推荐大家使用 docker exec 命令,因为此退出容器终端,不会导致容器的停止。
shijianzhongdeMacBook-Pro:~ shijianzhong$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dab2da3d3404 centos "/bin/bash" 4 minutes ago Up 4 minutes dreamy_engelbart shijianzhongdeMacBook-Pro:~ shijianzhong$ docker run -itd centos 88a6596beedc9ebe06429b1b70437c33bf89ad1172ec96330eec28cae41f6c1a shijianzhongdeMacBook-Pro:~ shijianzhong$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 88a6596beedc centos "/bin/bash" 7 seconds ago Up 6 seconds wonderful_borg dab2da3d3404 centos "/bin/bash" 8 minutes ago Up 8 minutes dreamy_engelbart shijianzhongdeMacBook-Pro:~ shijianzhong$ docker attach 88 [root@88a6596beedc /]# exit exit shijianzhongdeMacBook-Pro:~ shijianzhong$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dab2da3d3404 centos "/bin/bash" 8 minutes ago Up 8 minutes dreamy_engelbart shijianzhongdeMacBook-Pro:~ shijianzhong$
原文:https://www.cnblogs.com/sidianok/p/12856332.html