为什么Docker Nginx容器仍显示Defualt页面而不是提供的索引文件?

时间:2019-05-02 11:52:23

标签: docker nginx

我有一个docker项目的树输出。

├── code
│   ├── index.php
│   └── style.css
├── docker-compose.yml
├── mariadb
│   ├── dbs
│   └── Dockerfile
└── nginx
    ├── Dockerfile
    ├── lemp.docker.conf
    └── nginx.conf

使用nginx Dockerfile和两个conf文件的内容,我似乎无法理解我做错的地方。请指出。

nginx Dockerfile

FROM ubuntu:16.04
ENV REFRESHED_AT YYYY-MM-DD
RUN apt-get -yqq update; apt-get -yqq install nginx
ADD lemp.docker.conf /etc/nginx/conf.d/
ADD nginx.conf /etc/nginx/nginx.conf
EXPOSE 80

nginx CustomSite Conf

server {
listen 0.0.0.0:80;
server_name _;
root /var/www/html;
index index.php index.html index.htm;
access_log /var/log/nginx/default_access.log;
error_log /var/log/nginx/default_error.log;
}

nginx Conf

user www-data;
worker_processes 4;
pid /run/nginx.pid;
daemon off;
events { }
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
}

&最后是撰写文件

nginx:
 image: 'nginx:latest'
 ports:
  - '80:80'
 volumes:
  - ./code/:/var/www/html/
 links:
  - mariadb

mariadb:
 image: 'mariadb:latest'
 ports:
  - '3306:3306'
 volumes:
  - ./mariadb/dbs/:/var/lib/mysql/
 environment:
  - MYSQL_ROOT_PASSWORD=root.maria

1 个答案:

答案 0 :(得分:1)

我想那是因为default.conf仍然存在。您可以重写或删除它。

删除-

....
RUN apt-get -yqq update; apt-get -yqq install nginx
RUN  rm /etc/nginx/conf.d/default.conf
ADD lemp.docker.conf /etc/nginx/conf.d/
...

重写-

...
RUN apt-get -yqq update; apt-get -yqq install nginx
COPY lemp.docker.conf /etc/nginx/conf.d/default.conf
ADD nginx.conf /etc/nginx/nginx.conf
...

另一件事是,您在docker撰写YML文件中没有使用nginx的Dockerfile。因此,我看不到任何地方都可以使用您的nginx Dockerfile。那可能是另一个问题。撰写文件需要如下所示-

version: '3'

services:
  nginx:
    build:
      context: nginx
    ports:
      - '80:80'
    volumes:
      - ./code/:/var/www/html/
    links:
      - mariadb

  mariadb:
    image: 'mariadb:latest'
    ports:
      - '3306:3306'
    volumes:
      - ./mariadb/dbs/:/var/lib/mysql/
    environment:
      - MYSQL_ROOT_PASSWORD=root.maria