正文
启动容器
(base) @znwl-hp-z240-tower-workstation:~/图片$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESce26ce33d787 my_zip:tag “/bin/bash” 10 minutes ago Up 10 minutes dreamy_faraday8e11d4d78402 centos “/bin/bash” 43 hours ago Up 43 hours my_contain
(base) @znwl-hp-z240-tower-workstation:~/图片$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES83a83d03d872 my_zip:tag “/bin/bash” 6 minutes ago Exited (0) 29 seconds ago zip_movece26ce33d787 my_zip:tag “/bin/bash” 10 minutes ago Up 10 minutes dreamy_faradayd9b1b1dd242e my_zip:tag “/bin/bash” 3 hours ago Exited (0) 3 hours ago zipebcbd5e7caee centos “/bin/bash” 43 hours ago Exited (0) 43 hours ago elegant_jennings96cfe9dd4823 centos “/bin/bash” 43 hours ago Exited (0) 43 hours ago recursing_faraday8e11d4d78402 centos “/bin/bash” 43 hours ago Up 43 hours my_contain
(base) @znwl-hp-z240-tower-workstation:~/图片$ sudo docker exec -it zip_move /bin/bash
Error response from daemon: Container 83a83d03d872ac52ed196f468a4d3e2b94bb6d5a6220f962e61346311cfdb8e2 is not running
(base) @znwl-hp-z240-tower-workstation:~/图片$ sudo docker start zip_mobe Error response from daemon: No such container: zip_mobe
Error: failed to start containers: zip_mobe
(base) @znwl-hp-z240-tower-workstation:~/图片$ sudo docker start zip_move zip_move
(base) @znwl-hp-z240-tower-workstation:~/图片$ sudo docker exec -it zip_move /bin/bash
[root@83a83d03d872 /]# ls 0406.txt 1.txt bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var [root@83a83d03d872 /]# ^C
创建容器名字
docker run --name [自定义名称] [镜像名称]:[版本号]
创建容器并挂载
sudo docker run --name mounted -it -v /home/fangzhiming/mount/:/mnt my_zip:tag /bin/bash
将镜像my_zip:tag改名为mounted容器 注意默认my_zip:latest.有版本号需要附带上。:tag不可少。
/home/fangzhiming/mount/ 路径为宿主机
/mnt 路径为容器内部的文件夹
docker ps
sudo docker ps 查看正在运行的容器
sudo docker ps 查看所有的容器
如果
sudo docker ps 如果没有查到想要运行的容器,需要docker start 《容器名》
更改挂载路径
- docker stop nginx #停止容器
- systemctl stop docker#全部退出
- docker inspect nginx #查看容器ID
- cd /var/lib/docker/containers/容器ID
- 将该路径下:文件config.v2.json和hostconfig.json中的"Source"从/现有挂载路径—>更改为/需要挂载的路径
- systemctl start docker
- 启动nginx容器
- docker start nginx
- docker inspect -f “{{.Mounts}}” nginx#可以看到已经更改了