docker compose watch
https://docs.docker.com/compose/how-tos/file-watch/
Use Compose Watch
Introduced in Docker Compose version 2.22.0The
watch
attribute 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.
watch
adheres 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
.dockerignore
apply
- Use
ignore
option to define additional paths to be ignored (same syntax)- Temporary/backup files for common IDEs (Vim, Emacs, JetBrains, & more) are ignored automatically
.git
directories are ignored automaticallyYou don't need to switch on
watch
for 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
build
attribute. It doesn't track changes for services that rely on pre-built images specified by theimage
attribute.
https://stackoverflow.com/questions/78841344/what-is-difference-between-docker-compose-up-watch-and-docker-compose-watch
Actually,
docker compose up --watch
this commands will run the services which defined indocker-compose.yml
file and flag --watch enable watching for file changes.In the other hand,
docker compose watch
is 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 likeup
does.If you already up your services you can only run command
watch
, but if you're services is not yet installed you can usingcompose up
with flag--watch
to 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.yml
and reads all configured services, networks, volumes etc to create your Docker stack. If you also additionally have a file nameddocker-compose.override.yml
this will be read as well and used as an override file to complement. It works in the following order:
- All definitions from
docker-compose.yml
will be used- All definitions that are also defined in
docker-compose.override.yml
will automatically overwrite the settings fromdocker-compose.yml
- All definitions only available in
docker-compose.override.yml
will 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.yaml
and an optionalcompose.override.yaml
file. By convention, thecompose.yaml
contains 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
-f
option 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_db
The
compose.yaml
file might specify awebapp
service.webapp: image: examples/web ports: - "8000:8000" volumes: - "/data"
The
compose.admin.yaml
may also specify this same service:webapp: environment: - DEBUG=1
Any matching fields override the previous file. New values, add to the
webapp
service configuration:webapp: image: examples/web ports: - "8000:8000" volumes: - "/data" environment: - DEBUG=1
标签:files,Compose,two,compose,file,override,docker From: https://www.cnblogs.com/lightsong/p/18645318