Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker-compose copy config

I am trying to create a docker-compose for a project that requires a service to be running in the background. The image for service exists and this contains a config file, as well as an entrypoint ["/usr/bin/java", ...]

I would like to change the content of configuration file but I am not sure what would be the best way to do it without creating an extra dockerfile to just recreate image with appropriate files?

Since the entrypoint is /usr/bin/java , I am not sure how I would be able to use docker-compose's command to modify file content.

version: 2
services:
  myService:
    image: serviceA from registry
     # Would like to modify a config file's content...

  mainAPI:
     ...

Thank you

like image 477
meowDestroyer Avatar asked Jan 03 '23 01:01

meowDestroyer


1 Answers

You need to add a volumes reference in your docker-compose.yml.

version: 2
services:
  myService:
    image: serviceA from registry
     # Would like to modify a config file's content...
    volumes:
      - /path/to/host/config.conf:/path/to/container/config/to/overwrite/config.conf

  mainAPI:
     ...

Since 3.3, you can also create your own docker config file to overwrite the existing one. This is similar to above, except the docker config is now a copy of the original instead of binding to the host config file.

version: 3.3
services:
  myService:
    image: serviceA from registry
     # Would like to modify a config file's content...
    configs:
      - source: myconfigfile
        target: /path/to/container/config/to/overwrite/config.conf

  mainAPI:
     ...

configs:
  myconfigfile:
    file: ./hostconfigversion.conf

See https://docs.docker.com/compose/compose-file/#long-syntax for more info.

like image 70
Joel Magnuson Avatar answered Jan 05 '23 16:01

Joel Magnuson