I'm making a web application but I want to develop it in docker, but when I am using my container, the container files are not synchronized with the ones that are shown in the text editor, how can I solve that?
The files that are not synchronized are, for example, the migrations or the composer.json, that is, when I install a package through composer, those changes are not reflected in the text editor
Next, I provide my dockerfile and my docker compose.
BTW, I´m using Laravel 7.
Dockerfile
FROM composer:1.10.22 as build_stage
LABEL maintainer="Me"
COPY . /src
ADD .env.example /src/.env
WORKDIR /src
RUN composer install --no-ansi --no-interaction --no-progress --no-scripts --optimize-autoloader --ignore-platform-reqs
RUN php artisan key:generate
FROM php:7-fpm-alpine
ENV \
BUILD_PACKAGES="build-base curl-dev linux-headers" \
SQLITE_PACKAGES="zlib-dev libxml2-dev libxslt-dev postgresql postgresql-dev sqlite sqlite-libs sqlite-dev nano php7-gd php7-mysqli php7-zlib php7-curl"
RUN apk update && apk add $BUILD_PACKAGES && apk add $SQLITE_PACKAGES
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN composer --version && php -v
RUN set -ex \
&& apk --no-cache add \
postgresql-dev
RUN docker-php-ext-install pdo pdo_pgsql
COPY --from=build_stage /src /var/www/html
RUN chmod -R 777 /var/www/html
EXPOSE 5000
COPY ./run.sh /tmp
RUN chmod +x /tmp/run.sh
ENTRYPOINT ["/tmp/run.sh"]
docker-compose.yml
version: "3.4"
networks:
project-net:
volumes:
project-datastore:
services:
postgres-db:
image: postgres:11-alpine
volumes:
- project-datastore:/var/lib/postgresql/data
networks:
- project-net
ports:
- "25432:5432"
environment:
POSTGRES_DB: db
POSTGRES_USER: user
POSTGRES_PASSWORD: password
project:
build:
context: ./
image: project:latest
volumes:
- ./app:/var/www/html/app
- ./public:/var/www/html/public
- ./routes:/var/www/html/routes
- ./resources:/var/www/html/resources
depends_on:
- postgres-db
networks:
- project-net
ports:
- "5000:5000"
environment:
DATABASE_URL: postgres://user:password@postgres-db:5432/db
run.sh
cp /usr/share/zoneinfo/America/Mexico_City /etc/localtime
php artisan serve --host=0.0.0.0 --port=5000