1. 搜索nginx镜像
[root@192 ~]# docker search nginx
2. 拉取镜像
[root@192 ~]# docker pull nginx
查看是否下载成功:
[root@192 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5d0da3dc9764 10 days ago 231MB
tomcat latest bb832de23021 11 days ago 680MB
nginx latest ad4c705f24d3 2 weeks ago 133MB
mysql latest 0716d6ebcc1a 3 weeks ago 514MB
[root@192 ~]#
3. 启动nginx
[root@192 ~]# docker run -d --name nginx01 -p:3600:80 nginx ------------------启动nginx
978bc911ede446d6618a07ef76d4275f5f0f3885be6dda4e49cd9a5c6d78009a
[root@192 ~]# clear
[root@192 ~]# docker ps -----------------------查看是否启动成功
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
978bc911ede4 nginx "/docker-entrypoint.…" 4 seconds ago Up 3 seconds 0.0.0.0:3600->80/tcp, :::3600->80/tcp nginx01
[root@192 ~]# curl localhost:3600 -----------------本机测试
<!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>
[root@192 ~]#
参数说明:
-d 后台运行
--name 容器命名
-p 宿主机端口,容器内部端口
4. 网页测试
网页访问http://192.168.0.105:3600,其中192.168.0.105为我的服务器地址,3600为nginx代理端口。访问成功如下图所示: