当前位置: 首页>后端>正文

docker容器实用操作命令

启动nginx容器并挂载目录(提示-v使用有问题):

docker run -itd -p 808:80 -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf  -v /data/nginx/logs:/var/log/nginx --name nginxniubi nginx:latest

快速加载dockerFile

参考:https://blog.csdn.net/loveyouandc/article/details/119798525

docker build -t nginx:v //-t tag 打标签
docker build -f ../dockerfile -t nginx:v
docker pull dir/oneforall
docker run -it --rm -v ~/results:/OneForAll/results -v ~/.config:/OneForAll/config shmilylty/oneforall --target example.com run

查看容器

docker ps 
docker ps -a

启动容器

docker  start     历史容器ID
docker restart   容器ID或名称   //重启容器

创建容器只能挂载一个目录:

docker run -itd -p 80:80 -v /data/nginx/html:/usr/share/nginx/html --name nginxweb nginx

后面继续挂载(这种方式不行,是创建了很多):

docker run -itd -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf nginx /bin/bash
docker run -itd -v /data/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf nginx /bin/bash
docker run -itd -v /data/nginx/logs:/var/log/nginx nginx /bin/bash
docker run -itd -p 808:80 -v /data/nginx/html:/usr/share/nginx/html;/data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf;/data/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf;/data/nginx/logs:/var/log/nginx --name nginxniubi nginx:latest

要搞清楚镜像和容器的关系,容器能有多个,镜像只能有一个??

进入容器:

docker exec -it nginx-test /bin/bash

进入镜像:

docker run -it nginx /bin/bash

复制文件进容器:

docker cp /data/nginx/html/test.html nginx-test:/usr/share/nginx/html/test.html

这个报错(exec没有-v参数):

docker exec -it -v /data/nginx/html:/usr/share/nginx/html nginx-test /bin/bash

这个成功,这个是新建一个容器,name随机分配:

docker run -it -v /data/nginx/html:/usr/share/nginx/html nginx /bin/bash

https://www.xamrdz.com/backend/3fh1937944.html

相关文章: