1

I'm trying to mount a docker-compose with its respective dockerfile to have a project with a /backend/ folder where an API with laravel will go and then a /frontend/ folder where a react frontend goes. The goal is to build on it so I need to use volumes with persistent data.

The build does it perfectly and I can enter each of the dockers, the problems I have are:

  • The volumes are not persistent, that is, I make a change in the frontend directory (react) and I don't see the changes, I only see them if I do another build.
  • From the backend container I want to be able to access the DB to launch the Laravel migrations and I get an error that it can't find the schema.

Docker-compose.yaml

version: '3.7'
services:

  frontend:
    build:
      context: ./app-frontend
    ports:
      - "81:80"
    networks:
      - app-network

  backend:
    build:
      context: ./app-backend/
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_USER: ${DB_USERNAME}
    working_dir: /var/www
    volumes:
      - ./app-backend:/var/www
    ports:
      - "8001:8000"
    networks:
      - app-network
      - db

  appdb:
    image: mysql:5.7
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_USER: ${DB_USERNAME}
    volumes:
      - ./initdb:/docker-entrypoint-initdb.d
    ports:
      - "3307:3306"
    networks:
      - db

networks:
  app-network:
    driver: bridge
  db:

Dockerfile backend

FROM php:7.4-apache

RUN a2enmod rewrite

RUN apt-get update && apt-get install -y \
    libzip-dev \
    zlib1g-dev \
    libicu-dev \
    libxml2-dev \
    libpq-dev \
    vim \
    libpng-dev  \
    && docker-php-ext-install pdo pdo_mysql  zip intl xmlrpc soap opcache \
    && docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd


RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
COPY docker/php/https://php.ini /usr/local/etc/php
COPY docker/apache/https://apache2.conf /etc/apache2/https://apache2.conf
COPY docker/apache/https://vhost.conf /etc/apache2/sites-available/000-https://default.conf

ENV COMPOSER_ALLOW_SUPERUSER 1

COPY . /var/www

RUN chown -R www-data:www-data /var/www/html


WORKDIR /var/www
RUN composer install

Dockerfile frontend

FROM node:13.10.1-alpine
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
ENTRYPOINT npm start
ilernet
  • 194
  • 1
  • 2
  • 7

0 Answers0