docker练习一

练习

安装nginx

# 搜索nginx镜像
docker search nginx
# 下载镜像
docker pull nginx
# 启动镜像
docker run -d --name nginx01 -p 7788:80 nginx
#运行测试
curl localhost:7788

# 结果
[root@localhost ~]# docker run -d --name nginx01 -p 7788:80 nginx
a54f6129cf015394e77a4bbf9fc387b2ece8056166bd4f391dcd1d7faffc42c7
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES
a54f6129cf01   nginx     "/docker-entrypoint.…"   4 seconds ago   Up 2 seconds   0.0.0.0:7788->80/tcp, :::7788->80/tcp   nginx01
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES
a54f6129cf01   nginx     "/docker-entrypoint.…"   6 seconds ago   Up 5 seconds   0.0.0.0:7788->80/tcp, :::7788->80/tcp   nginx01
[root@localhost ~]# curl localhost:7788                          
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

关于docker端口暴露的图解

关于docker端口暴露的图解

关于这个练习的思考:

在部署好nginx之后,我们需要进入容器中对nginx做各种配置,如果多次进行配置调整的话,我们这样进入是很麻烦的,而且,当docker损坏,或者误删了,那么也会造成配置和数据丢失,这样是我们不乐意见到的。那么我们可以把宿主机上面的某一个目录的配置映射到容器中吗?这样就算出现以上问题,我们也可以很快的恢复容器。并且修改配置直接在宿主机上面进行即可。

以上资料来源:
https://www.bilibili.com/video/BV1og4y1q7M4?p=14

posted @ 2022-01-16 17:06  影梦无痕  阅读(34)  评论(0)    收藏  举报