Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

733
Vistas
Docker COPY not updating files when rebuilding container

I have a docker-compose-staging.yml file which I am using to define a PHP application. I have defined a data volume container (app) in which my application code lives, and is shared with other containers using volumes_from.

docker-compose-staging.yml:

version: '2'
services:
    nginx:
        build:
            context: ./
            dockerfile: docker/staging/nginx/Dockerfile
        ports:
            - 80:80
        links:
            - php
        volumes_from:
            - app

    php:
        build:
            context: ./
            dockerfile: docker/staging/php/Dockerfile
        expose:
            - 9000
        volumes_from:
            - app

    app:
        build:
            context: ./
            dockerfile: docker/staging/app/Dockerfile
        volumes:
            - /var/www/html
        entrypoint: /bin/bash

This particular docker-compose-staging.yml is used to deploy the application to a cloud provider (DigitalOcean), and the Dockerfile for the app container has COPY commands which copy over folders from the local directory to the volume defined in the config.

docker/staging/app/Dockerfile:

FROM php:7.1-fpm
COPY ./public /var/www/html/public
COPY ./code /var/www/html/code

This works when I first build and deploy the application. The code in my public and code directories are present and correct on the remote server. I deploy using the following command:

docker-compose -f docker-compose-staging.yml up -d

However, next I try adding a file to my local public directory, then run the following command to rebuild the updated code:

docker-compose -f docker-compose-staging.yml build app

The output from this rebuild suggests that the COPY commands were successful:

Building app
Step 1 : FROM php:7.1-fpm
 ---> 6ed35665f88f
Step 2 : COPY ./public /var/www/html/public
 ---> 4df40d48e6a5
Removing intermediate container 7c0fbbb7f8b6
Step 3 : COPY ./code /var/www/html/code
 ---> 643d8745a479
Removing intermediate container cfb4f1a4f208
Successfully built 643d8745a479

I then deploy using:

docker-compose -f docker-compose-staging.yml up -d

With the following output:

Recreating docker_app_1
Recreating docker_php_1
Recreating docker_nginx_1

However when I log into the remote containers, the file changes are not present.

I'm relatively new to Docker so I'm not sure if I've misunderstood any part of this process! Any guidance would be appreciated.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

This is because of cache.

Run,

docker-compose build --no-cache

This will rebuild images without using any cache.

And then,

docker-compose -f docker-compose-staging.yml up -d
over 4 years ago · Santiago Trujillo Denunciar

0

I was struggling with the fact that migrations were not detected nor done. Found this thread and noticed that the root cause was, indeed, files not being updated in the container. The force-recreate solution suggested above solved the problem for me, but I find it cumbersome to have to try to remember when to do it and when not. E.g. Vue related files seem to work just fine but Django related files don't.

So I figured why not try adjusting the Docker file to clean up the previous files before the copy:

RUN rm -rf path/to/your/app
COPY . path/to/your/app

Worked like a charm. Now it's part of the build and all you need is run the docker-compose up -d --build again. Files are up to date and you can run make migrations and migrate against your containers.

over 4 years ago · Santiago Trujillo Denunciar

0

I had similar issue if not same while working on dotnet core application.

What I was trying to do was rebuild my application and get it update my docker image so that I can see my changes reflected in the containerized copy.

So I got going by removing the underlying image generated by docker-compose up using the command to get my changes reflected:

docker rmi *[imageId]*

I believe there should be support for this in docker-compose but this was enough for my need at the moment.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda