在docker中使用nginx

  1. 查看可用的nginx版本
$ docker search nginx
NAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                              Official build of Nginx.                        14744     [OK]       
jwilder/nginx-proxy                Automated Nginx reverse proxy for docker con…   2016                 [OK]
...
  1. 拉取nginx镜像
$ docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
f7ec5a41d630: Pull complete 
aa1efa14b3bf: Pull complete 
b78b95af9b17: Pull complete 
c7d6bca2b8dc: Pull complete 
cf16cd8e71e0: Pull complete 
0241c68333ef: Pull complete 
Digest: sha256:75a55d33ecc73c2a242450a9f1cc858499d468f077ea942867e662c247b5e412
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
  1. 查看本地镜像
$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
nginx        latest    62d49f9bab67   7 days ago   133MB
  1. 运行
$ docker run --name nginx-test -p 127.0.0.1:8080:80 -d nginx
42a59b7e75bbf8e1e0ffe8ec6e5b9c78d11a83bf6fa543a569986d6862b50cb7
$ docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                  NAMES
42a59b7e75bb   nginx     "/docker-entrypoint.…"   19 seconds ago   Up 18 seconds   127.0.0.1:8080->80/tcp   nginx-test
  1. 测试
$ curl 127.0.0.1:8080
<!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>
  1. 查看标准输出
    -f: 让 docker logs 像使用 tail -f 一样来输出容器内部的标准输出。
$ docker logs -f 42a59b7e75bb
...
172.17.0.1 - - [21/Apr/2021:04:31:08 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
  1. 查看端口
$ docker port 42a59b7e75bb
80/tcp -> 127.0.0.1:8080
  1. 查看进程
$ docker top 42a59b7e75bb
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                12206               12164               0                   12:28               ?                   00:00:00            nginx: master process nginx -g daemon off;
101                 12283               12206               0                   12:28               ?                   00:00:00            nginx: worker process
  1. docker下nginx的配置
    使用本地配置文件覆盖docker配置文件,我的私有配置文件都在conf.d目录下
docker run --name nginx -p 80:80 -v /etc/nginx/conf.d:/etc/nginx/conf.d -d nginx
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值