Docker 安装 Nginx

Docker 安装 Nginx

runoob@runoob:~/nginx$ docker search nginx
NAME                      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                     Official build of Nginx.                        3260      [OK]       
jwilder/nginx-proxy       Automated Nginx reverse proxy for docker c...   674                  [OK]
richarvey/nginx-php-fpm   Container running Nginx + PHP-FPM capable ...   207                  [OK]
million12/nginx-php       Nginx + PHP-FPM 5.5, 5.6, 7.0 (NG), CentOS...   67                   [OK]
maxexcloo/nginx-php       Docker framework container with Nginx and ...   57                   [OK]
  • 这里我们拉取官方的镜像
docker pull nginx
  • 等待下载完成后,我们就可以在本地镜像列表里查到 REPOSITORY 为 nginx 的镜像。
runoob@runoob:~/nginx$ docker images nginx
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              555bbd91e13c        3 days ago          182.8 MB
  • 以下命令使用 NGINX 默认的配置来启动一个 Nginx 容器实例:
$ docker run --name runoob-nginx-test -p 8081:80 -d nginx

runoob-nginx-test容器名称。
the -d设置容器在在后台一直运行。
the -p端口进行映射,将本地 8081 端口映射到容器内部的 80 端口。
执行以上命令会生成一串字符串,类似6dd4380ba70820bd2acc55ed2b326dd8c0ac7c93f68f0067daecad82aef5f938,这个表示容器的 ID,一般可作为日志的文件名。
我们可以使用 docker ps 命令查看容器是否有在运行:

$ docker ps
CONTAINER ID        IMAGE        ...               PORTS                  NAMES
6dd4380ba708        nginx        ...      0.0.0.0:8081->80/tcp   runoob-nginx-test

nginx 部署

首先,创建目录 nginx, 用于存放后面的相关东西。

$ mkdir -p ~/nginx/www ~/nginx/logs ~/nginx/conf

拷贝容器内 Nginx 默认配置文件到本地当前目录下的 conf 目录,容器 ID 可以查看docker ps命令输入中的第一列:

docker cp 6dd4380ba708:/etc/nginx/nginx.conf ~/nginx/conf
    • www: 目录将映射为 nginx 容器配置的虚拟目录。
    • logs: 目录将映射为 nginx 容器的日志目录。
    • conf: 目录里的配置文件将映射为 nginx 容器的配置文件。
      部署命令
      “`
















posted @ 2020-08-29 13:43  雨夜的博客  阅读(275)  评论(0编辑  收藏  举报