#搜索镜像 search 建议大家去官网可以看到帮助文档
#下载镜像 pull 后面加上要下载的镜像名称(Nginx)
#运行测试
[root@localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest c8562eaf9d81 6 days ago 546MB
redis latest 621ceef7494a 11 days ago 104MB
nginx latest f6d0b4767a6c 12 days ago 133MB
centos latest 300e315adb2f 6 weeks ago 209MB
hello-world latest bf756fb1ae65 12 months ago 13.3kB
可以看到我们已经把nginx镜像下载完成,下面运行即可,在运行前,我们需要在自己的本地虚拟机上开一个可以访问的端口,最后映射到nginx的默认端口上,我们就可以访问了
[root@localhost /]# firewall-cmd --zone=public --add-port=1935/tcp
success
#用以上命令可以在本地的虚拟机上开一个端口
# -d 是后台运行
# --name 是给运行的nginx起的别名
# -p 宿主机端口:容器内部端口
[root@localhost /]# docker run -d --name nginx01 -p 1935:80 nginx
a975207b26e2e7682aeff399e39e0aaf80117a757fcc3eb23c6bddd6c738a8ef #这是开启成功的容器id
[root@localhost /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a975207b26e2 nginx "/docker-entrypoint.…" 4 minutes ago Up 4 minutes 0.0.0.0:1935->80/tcp nginx01
#我们可以看到nginx启动成功
#测试nginx是否可以访问
[root@localhost /]# curl localhost:1935
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
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>
#我们可以看到也可以访问,我们再通过外网访问一下,看是否成功
image-20210125163202453.png
#进入容器
[root@localhost /]# docker exec -it nginx01 /bin/bash
root@a975207b26e2:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@a975207b26e2:/# cd /etc/nginx
root@a975207b26e2:/etc/nginx# ls
conf.d fastcgi_params koi-utf koi-win mime.types modules nginx.conf scgi_params uwsgi_params win-utf
root@a975207b26e2:/etc/nginx#
#我们可以看到nginx的配置文件等信息
网友评论