2

I'm testing docker compose with Nginx and php-fpm, but this fail. My docker-compose.yml:

version: '2'

services:

  nginx:
    container_name: nginx
    build:
      context: ./dockerfiles/nginx/
      dockerfile: Dockerfile
    volumes:
      - ./project/:/usr/share/nginx/html/
    ports:
      - "8000:80"
    links:
      - php

  php:
    container_name: php-fpm
    image: php:7-fpm
    volumes:
      - ./project/:/var/www/html/
    ports:
      - "9000:9000"

This is my dockerfile Nginx:

FROM nginx:latest
COPY config/default.conf /etc/nginx/conf.d/

And dafault.conf file:

server {
  listen 80;

  server_name localhost;

  root /usr/share/nginx/html;

  location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/.+\.php(/|$) {
        fastcgi_pass php:9000;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

when I try localhost: 8000 returns the following message:

"File not found."

but, the index.php is in the project/ path.

that I am wrong?

1 Answer 1

3

I think you need to use volumes_from in your nginx container in the compose file, now you have in nginx:

volumes:
  - ./project/:/usr/share/nginx/html/

And in php

volumes:
  - ./project/:/var/www/html/

They should be the same.

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

1 Comment

the problem was both must point to the same volume. for example: /var/www/html

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.