1

I'm trying to use docker-compose for deployment of my React app, which uses an express backend and Postgres Database. My idea is to have shared volumes from my docker-compose. Then build from my Dockerfile into the volume, so that Nginx will be able to serve the files. The problem now is that it works when i build the project the first time, but if I change something in my React Client and run "docker-compose up --build" it looks like everything is building as it should, but the files served are still the same. Is COPY command in my dockerfile not overwriting the old files?

Dockerfile in my React Client Project

FROM node:13.12.0-alpine as build
WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
RUN npm install
COPY . ./
RUN npm run build
FROM node:13.12.0-alpine
COPY --from=build /app/build /var/lib/frontend

docker-compose

version: "3.7"
services:
 callstat_backend:
  build: ./callstat-backend
  restart: always
  ports:
    - "3000:3000"
  env_file:
   - keys.env
  depends_on:
  - postgres
 callstat_frontend:
  build: ./callstat-client
  volumes:
   - frontend/:/var/lib/frontend
 postgres:
  image: postgres:11.2-alpine
  ports:
   - "5432:5432"
  volumes:
   - pgdata:/var/lib/postgresql/data
  environment:
   POSTGRES_USER: postgres
   POSTGRES_PASSWORD: postgres
   POSTGRES_DB: callstat
 nginx:
  image: nginx
  volumes:
   - frontend:/usr/share/nginx/html
   - ./nginx.conf:/etc/nginx/conf.d/default.conf
  ports:
   - "80:80"
  depends_on:
   - callstat_frontend
volumes:
 pgdata:
 frontend:

Maybe i'm taking a totaly wrong approach here?

2
  • 1
    docker automatically does not refreshes the volume if it already exists. So when you are doing docker_compose up -d second time, since the volume already exists, it is being used as it is Commented Apr 11, 2020 at 2:00
  • Can I change something to achieve this? I’m running “docker-compose up --build”, and I can see the build process happening. But the files in the volume is not changed at all since first start. Any other pattern I can take to solve this problem? Commented Apr 11, 2020 at 6:16

1 Answer 1

2

You can run the commands in the following order:

# stop down the services
docker-compose stop

# remove the previously created docker resources
docker-compose rm

# bring up the services again
docker-compose up --build

This was your previous volume be removed and new one will be created with the updated changes.

NOTE: This is okay from the development perspective, but docker volumes are really expected to persist between deployments. For artifacts like code changes ideally images should be published as part of build process. To get little more insight into this topic you can refer to https://github.com/docker/compose/issues/2127

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.