Stay Hungry,Stay Foolish!

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.0

The 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 automatically

You 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 the image 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 in docker-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 like up does.

If you already up your services you can only run command watch, but if you're services is not yet installed you can using compose 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 named docker-compose.yml and reads all configured services, networks, volumes etc to create your Docker stack. If you also additionally have a file named docker-compose.override.yml this will be read as well and used as an override file to complement. It works in the following order:

  1. All definitions from docker-compose.yml will be used
  2. All definitions that are also defined in docker-compose.override.yml will automatically overwrite the settings from docker-compose.yml
  3. 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 optional compose.override.yaml file. By convention, the compose.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 a webapp 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

 

 




posted @   lightsong  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
历史上的今天:
2023-01-01 D - Scope --- ATCODER
2023-01-01 C. On Number of Decompositions into Multipliers -- Codeforces
2020-01-01 npm scripts
2020-01-01 especially VS particularly
2017-01-01 lua UT测试工具
2017-01-01 LuaSrcDiet工具介绍(lua源码处理软件)
千山鸟飞绝,万径人踪灭
点击右上角即可分享
微信分享提示