Laravel – Docker: ERROR Cannot start service nginx: OCI runtime create failed

dockerlaravelnginx

I'm using docker-compose for nginx service, here is the docker-compose.yml file:

version: '3'

networks:
  laravel:


services:
  nginx:
    image: nginx:stable-alpine
    container_name: nginx
    networks:
      - laravel
    ports:
      - "8088:80"
    volumes:
      - ./src:/var/www/html
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php
      - mysql


  mysql:
    image: mysql:5.7.22
    container_name: mysql
    restart: unless-stopped
    tty: true
    ports:
      - "4306:3306"
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      MYSQL_DATABASE: homestead
      MYSQL_USER: root
      MYSQL_PASSWORD: secret
      MYSQL_ROOT_PASSWORD: secret
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    networks:
      - laravel

  php:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: php
    volumes:
      - ./src:/var/www/html
    ports:
        - "9000:9000"
    networks:
      - laravel

This is the default.conf file

server{
    listen 80;
    index index.php index.html index.htm;
    server_name localhost;
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/html/public;

    location / {
        try_files $uri $uri/ /index.php?query_string;
    }


    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

This is the result of docker-compose up:

ERROR: for nginx Cannot start service nginx: OCI runtime create
failed: container_linux.go:346: starting container process caused
"process_linux.go:449: container init caused \"rootfs_linux.go:58:
mounting \\"/d/wamp64/www/instawash/nginx/default.conf\\" to rootfs
\\"/mnt/sda1/var/lib/docker/overlay2/a0da06d30448a2583f346955c853cd3343982d96fb5e81b23be4cabad75a3c6b/merged\\"
at
\\"/mnt/sda1/var/lib/docker/overlay2/a0da06d30448a2583f346955c853cd3343982d96fb5e81b23be4cabad75a3c6b/merged/etc/nginx/conf.d/default.conf\\"
caused \\"not a directory\\"\"": unknown: Are you trying to mount a
directory onto a file (or vice-versa)? Check if the specified host
path exists and is the expected type

Tree directory:

    ├─── mysql/
    ├─── nginx/
    └─── src/
         docker-compose.yml
         Dockerfile

Best Answer

The target of a volume in a docker-compose file can't be a file, it must be a directory.

So instead of this :

  - ./nginx/default.conf:/etc/nginx/conf.d/default.conf

You probably want this :

  - ./nginx/default.conf:/etc/nginx/conf.d  

See : https://docs.docker.com/storage/volumes/

Related Topic