Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

PlasticHeart's avatar

How do I make my container sync the files I make? (docker)

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
0 likes
9 replies
Sinnbeck's avatar

These are the folders you want to sync. Any folder not in the list won't be synced

volumes:
      - ./app:/var/www/html/app
      - ./public:/var/www/html/public
      - ./routes:/var/www/html/routes
      - ./resources:/var/www/html/resources

To just sync everything you can do

volumes:
  - ./:/var/www/html 
PlasticHeart's avatar

@Sinnbeck But what should I put there, because I have tried to put ./:/var/www/html but I get an error when I run it. Warning: require(/var/www/html/vendor/autoload.php): failed to open stream: No such file or directory in /var/www/html/artisan on line 18 and Fatal error: require(): Failed opening required '/var/www/html/vendor/autoload.php' (include_path='.:/usr/local/lib/php') in /var/www/html /artisan online 18

Sinnbeck's avatar

@PlasticHeart for this container yes. Be careful not rebuilding volumes for postgres, or you will loose the database with data

Sinnbeck's avatar

@PlasticHeart I cannot remember the syntax completely but something like (-v for volumes)

docker-compose down project -v
docker-compose up -d

But you might want to export the database if it holds important information

1 like
Sinnbeck's avatar

@PlasticHeart and be sure to run composer install and npm install after it's you start it up again as the files will be either gone or out of date

Please or to participate in this conversation.