Docker 镜像使用

BBigSun 评论246阅读模式

1、拉取镜像

docker pull nginx:latest

2、查看镜像

docker images

3、启动容器

浏览器输入当前服务器IP

1、最基本的文章源自十年又十年-https://www.bbigsun.com/310.html

docker run -itd --name nginx -p 80:80 nginx:latest

2、挂载目录(保存配置文件和代码)文章源自十年又十年-https://www.bbigsun.com/310.html

提前创建 /opt/nginx/html/opt/nginx/conf 目录文章源自十年又十年-https://www.bbigsun.com/310.html

docker run -itd --name nginx -p 80:80 -v /opt/nginx/html:/usr/share/nginx:/html -v /opt/nginx/conf:/etc/nginx/conf nginx:latest

当你修改本地 /opt/nginx/html/opt/nginx/conf 目录中的文件时,容器内也随之改变文章源自十年又十年-https://www.bbigsun.com/310.html

4、连接容器

这里使用容器名字进行连接,也可使用容器ID,将 nginx 改为容器ID即可。文章源自十年又十年-https://www.bbigsun.com/310.html

docker exec -it nginx bash

5、退出容器

exit

6、修改 nginx 容器中代码

cd /opt/nginx/
git clone https://gitee.com/bbigsun/docsify-template.git
rm -rf html
mv docsify-template html

7、导出 nginx 容器快照

docker export nginx > web.v1.zip

8、将 nginx 容器快照导入镜像

cat web.v1.zip | docker import - web:v1

9、停止 nginx 容器

docker stop nginx

10、验证新制作的 web:v1 镜像

docker run -itd --rm --name web-v1 web:v1

11、停止所有容器

docker stop docker ps -q

12、删除所有容器

docker rm docker ps -aq
文章源自十年又十年-https://www.bbigsun.com/310.html文章源自十年又十年-https://www.bbigsun.com/310.html

纸上得来终觉浅,绝知此事要躬行。

weinxin
17688689121
我的微信
微信扫一扫
Docker最后更新:2024-5-11
BBigSun
  • 本文由 BBigSun 发表于 2023年 3月 15日 17:17:33
  • 转载请务必保留本文链接:https://www.bbigsun.com/310.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定