Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose—bind mount volume only in development

I have a docker-compose.yml like that:

version: '2'
services:
  backend:
    build:
      context: .
    volumes:
      - .:/home/ll/stuff
    ports:
      - '8000:80'

That always mounts the volume, what is nice for development, but not for production. Is there a way to »tell« docker-compose to mount that volume only in development, or in other words, if APP_ENV is empty or ==development?

Do I need to create another compose file for that? If so, can I use the configuration from the production file, without repeating stuff that does not change?

like image 579
philipp Avatar asked Oct 19 '25 14:10

philipp


1 Answers

From official docs: Modify your compose file for production

consider defining an additional Compose file, say production.yml, which specifies production-appropriate configuration. This configuration file only needs to include the changes you’d like to make from the original Compose file. The additional Compose file can be applied over the original docker-compose.yml to create a new configuration.

Once you’ve got a second configuration file, tell Compose to use it with the -f option:

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

it should do the trick!

like image 129
Juliatzin Avatar answered Oct 22 '25 05:10

Juliatzin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!