Docker安装Nginx

Docker 安装Nginx

  • 搜索镜像
docker search nginx
  • 下载镜像
docker pull nginx
  • 查看镜像是否下载成功
docker images

REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
nginx        latest    4f380adfc10f   13 days ago    133MB
  • 运行镜像
docker run -d --name nginx01 -p 80:80 nginx
# 参数解释
# -d 后台运行
# --name给容器重命名
# -p 宿主机端口:容器内部端口
  • 查看nginx容器是否启动
docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                               NAMES
62c9a70b60fa   nginx     "/docker-entrypoint.…"   12 seconds ago   Up 10 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   nginx01
  • 命令行查看nginx是否启动
curl localhost:80

<!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>
  • 进入容器
docker exec -it nginx01 /bin/bash
root@62c9a70b60fa:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
posted @ 2021-07-06 19:35  phper-liunian  阅读(57)  评论(0编辑  收藏  举报