docker compose two policies
docker compose watch
https://docs.docker.com/compose/how-tos/file-watch/
Use Compose Watch
Introduced in Docker Compose version 2.22.0The
watchattribute automatically updates and previews your running Compose services as you edit and save your code. For many projects, this enables a hands-off development workflow once Compose is running, as services automatically update themselves when you save your work.
watchadheres to the following file path rules:
- All paths are relative to the project directory
- Directories are watched recursively
- Glob patterns aren't supported
- Rules from
.dockerignoreapply
- Use
ignoreoption to define additional paths to be ignored (same syntax)- Temporary/backup files for common IDEs (Vim, Emacs, JetBrains, & more) are ignored automatically
.gitdirectories are ignored automaticallyYou don't need to switch on
watchfor all services in a Compose project. In some instances, only part of the project, for example the Javascript frontend, might be suitable for automatic updates.Compose Watch is designed to work with services built from local source code using the
buildattribute. It doesn't track changes for services that rely on pre-built images specified by theimageattribute.
https://stackoverflow.com/questions/78841344/what-is-difference-between-docker-compose-up-watch-and-docker-compose-watch
Actually,
docker compose up --watchthis commands will run the services which defined indocker-compose.ymlfile and flag --watch enable watching for file changes.In the other hand,
docker compose watchis only watch for changes in the source code and rebuild or restart containers when changes are detected. The focus point is, this command watching changes without initially starting the services likeupdoes.If you already up your services you can only run command
watch, but if you're services is not yet installed you can usingcompose upwith flag--watchto see the files changes.I hope this simple answer can help you. :)
docker-compose.override.yml
https://devilbox.readthedocs.io/en/latest/configuration-files/docker-compose-override-yml.html#copy-example-file
How does docker-compose.override.yml work?
When you run
docker-compose up, it searches for a file nameddocker-compose.ymland reads all configured services, networks, volumes etc to create your Docker stack. If you also additionally have a file nameddocker-compose.override.ymlthis will be read as well and used as an override file to complement. It works in the following order:
- All definitions from
docker-compose.ymlwill be used- All definitions that are also defined in
docker-compose.override.ymlwill automatically overwrite the settings fromdocker-compose.yml- All definitions only available in
docker-compose.override.ymlwill be added additionally.For starting up your Docker Compose stack there are no additional steps or command line arguments required. If both files exist, they will be read automatically.
https://docs.docker.com/compose/how-tos/multiple-compose-files/merge/
Merge Compose files
Docker Compose lets you merge and override a set of Compose files together to create a composite Compose file.
By default, Compose reads two files, a
compose.yamland an optionalcompose.override.yamlfile. By convention, thecompose.yamlcontains your base configuration. The override file can contain configuration overrides for existing services or entirely new services.If a service is defined in both files, Compose merges the configurations using the rules described below and in the Compose Specification.
How to merge multiple Compose files
To use multiple override files, or an override file with a different name, you can either use the pre-defined COMPOSE_FILE environment variable, or use the
-foption to specify the list of files.Compose merges files in the order they're specified on the command line. Subsequent files may merge, override, or add to their predecessors.
For example:
docker compose -f compose.yaml -f compose.admin.yaml run backup_dbThe
compose.yamlfile might specify awebappservice.webapp: image: examples/web ports: - "8000:8000" volumes: - "/data"The
compose.admin.yamlmay also specify this same service:webapp: environment: - DEBUG=1Any matching fields override the previous file. New values, add to the
webappservice configuration:webapp: image: examples/web ports: - "8000:8000" volumes: - "/data" environment: - DEBUG=1

浙公网安备 33010602011771号