0

I'm running Nginx inside Docker and from logs, I can see that Nginx cannot find mime.types file. The line from Nginx.conf:

include      mime.types; 

Here is the Dockerfile.

FROM nginx:alpine
COPY . ./etc/nginx
RUN ls -la /etc/nginx

Here is the list of files in the working directory:

drwxr-xr-x    1 root     root          4096 Jul 30 07:35 .
drwxr-xr-x    1 root     root          4096 Jul 30 07:35 ..
-rw-r--r--    1 root     root            58 Jul 29 21:48 Dockerfile
drwxr-xr-x    2 root     root          4096 Jul 29 21:36 certs
drwxr-xr-x    2 root     root          4096 Jul  6 19:40 conf.d
-rw-r--r--    1 root     root          1077 Jul  6 15:21 fastcgi.conf
-rw-r--r--    1 root     root          1007 Jul  6 15:21 fastcgi_params
-rw-r--r--    1 root     root          5290 Jul  6 15:21 mime.types
lrwxrwxrwx    1 root     root            22 Jul  6 19:40 modules -> /usr/lib/nginx/modules
-rw-r--r--    1 root     root         10729 Jul 30 07:35 nginx.conf
-rw-r--r--    1 root     root           636 Jul  6 15:21 scgi_params
-rw-r--r--    1 root     root           664 Jul  6 15:21 uwsgi_params

And this is the error log:

2021/07/30 07:35:34 [emerg] 1#1: open() "/etc/nginx/mime.types" failed (2: No such file or directory) in /etc/nginx/nginx.conf:52

I can clearly see that nginx.conf is in the same directory but couldn't be found.

Docker compose

version: "3.7"
services:
  proxy:
    build: nginx
    container_name: nginx
    ports:
      - '443:443'
    volumes:
      # - ./nginx:/etc/nginx
      # - /etc/nginx/certs

    restart: 'always'
    networks:
      - react-express
  frontend:
    build: ui
    expose:
      - 3000
    stdin_open: true
    volumes:
      - ./ui:/usr/src/ui
      - /usr/src/ui/node_modules
    container_name: ui
    restart: always
    networks:
      - react-express
    depends_on:
      - backend

  backend:
    container_name: api
    restart: always
    build: api
    volumes:
      - ./api:/usr/src/app
      - /usr/src/app/node_modules
    networks:
      - react-express
    expose: 
      - 8080
networks:
  react-express:
8
  • Try removing the leading dot in COPY . ./etc/nginx, i.e. try with COPY . /etc/nginx. Commented Jul 30, 2021 at 8:13
  • @MarkoE, good point, but doesn't help. Commented Jul 30, 2021 at 8:15
  • How about adding this to nginx.conf: include /etc/nginx/mime.types; instead of only mime.types? Commented Jul 30, 2021 at 8:22
  • @MarkoE, nope, still the same error, that is very weird actually. Commented Jul 30, 2021 at 8:38
  • 1
    @andrey.shedko When you map ./nginx:/etc/nginx, the volume mapping wins and 'hides' the files in the image. Commented Jul 30, 2021 at 9:34

1 Answer 1

1

As you say in the comment, you map a directory to /etc/nginx when you run the container.

When you map ./nginx:/etc/nginx, the volume mapping wins and 'hides' the files in the image.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, but what is the proper way to fix this issue?
There are probably a number of ways to fix it. Can you include all the files in the image, so you don't need to map a volume? Can you instead have all the files in your host directory, so there are no files in the image to hide? Maybe you place mime.types outside the /etc/nginx path and change nginx.conf to point at it. I don't know what would work best in your case.
If you only map a few files, you could create volume mappings for each of them. Or you could create symlinks for the files you want to map in /etc/nginx/ in the image to a different directory, and then create a mapping for that directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.