How to rename and delete a file in a Dockerfile

Viewed 12274

Locally when docker copies file, I have a folder that has 2 files:

database.yml database.docker.yml

When I run docker-compose up I want to delete the file database.yml and then rename the other file database.docker.yml to database.yml

This is what I have now but it isn't working:

ADD . /app
RUN rm /app/config/database.yml
RUN mv /app/config/database.docker.yml /app/config/database.yml

My docker-compose for this service is:

rails:
    build: ../rails-web
    volumes:
     - ../rails-web:/app
    ports:
      - "3000:3000"
    depends_on:
      - db
    command: puma -C config/puma.rb
    env_file:
      - '.env'
1 Answers

Your problem is that during build you add /app, remove the old config and move the new config. But then docker-compose up starts the container and you overwrite the /app folder with your local one - by mapping it with your volumes directive.

Fix? EITHER remove volumes from docker-compose.yml -- but in this case you will have to rebuild the image every time you introduce changes to your code. OR rewrite volumes like this:

rails:
    ...
    volumes:
     - ../rails-web:/app
     - ../rails-web/config/database.docker.yml:/app/config/database.yml
    ...

It will map the docker config to your "old" config.

Related