MartinZeltin
6 months ago
28355
6
Servers

I don't understand why I need to mount Docker volumes for both Nginx and PHP

Posted 6 months ago by MartinZeltin

I have a simple Laravel application with Nginx, PHP and MySQL each in its own container. What I don't understand is:

  1. why do I need to mount volumes for both my Nginx and also PHP? Isn't PHP only a programming language not a server?

  2. Also, for production do I need to COPY my src to /var/www/html but do I need to do it for both Nginx and PHP? Or only for Nginx?

Here is my docker-compose-dev.yml file

version: '3'

networks:
  laravel:

services:
  nginx:
    image: nginx:stable-alpine
    
    container_name: nginxcontainer
    
    ports:
      - "8088:80"

    volumes:
      - ./src:/var/www/html
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf

    depends_on:
      - php
      - mysql

    networks:
      - laravel

  mysql:
    image: mysql:5.7.22

    container_name: mysqlcontainer

    restart: unless-stopped

    tty: true

    ports:
      - "4306:3306"

    volumes:
      - ./mysql:/var/lib/mysql

    environment:
      MYSQL_DATABASE: homestead
      MYSQL_USER: homestead
      MYSQL_PASSWORD: secret
      MYSQL_ROOT_PASSWORD: secret
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql

    networks:
      - laravel

  php:
    build:
      context: .
      dockerfile: php/Dockerfile-dev
    
    container_name: phpcontainer

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

    ports:
      - "9000:9000"

    networks:
      - laravel

and here is my php/Docker-dev file

FROM php:7.2-fpm-alpine

RUN docker-php-ext-install pdo pdo_mysql
RUN chown -R www-data:www-data /var/www
RUN chmod 755 /var/www

Please sign in or create an account to participate in this conversation.