docker创建nginx镜像
1.docker仓库中搜索nginx镜像。
[root@localhost ~]# docker search nginx
2.下载nginx镜像,这里我们选择下载人数最多的镜像版本。
[root@localhost ~]# docker pull docker.io/nginx
3.查看nginx是否下到本地
[root@localhost ~]# docker images |grep -i nginx #-i 忽略字符大小写
4.基于本地nginx镜像启动nginx web服务
[root@localhost ~]# docker run -itd -p80:80 docker.io/nginx
# run 全新启动一台容器
# -i interactive交互模式
# -t tty打开一个终端
# -d daemon后台启动
# -p 开启DNAT映射,讲宿主机80端口映射至容器的80,用户访问宿主机的80,即是访问
容器的80
5.查看已启动nginx容器
[root@localhost ~]# docker ps
6.查看nginx容器的ip地址
[root@localhost ~]# docker inspect e9aedca5f8f4 |grep -i ipaddr|tail -1|awk -F" '{print $4}'
172.17.0.2
7.访问nginx容易中web服务
[root@localhost ~]# curl 172.17.0.2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
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>