ãã®ã¨ã³ããªã¯ãã¯ã¦ãªã¨ã³ã¸ã㢠- Qiita Advent Calendar 2024 - Qiitaã®13æ¥ç®ã®è¨äºã§ããæ¨æ¥ã¯ã id:maiyama4 ããã®SwiftUI ã® Text ããªããçç¥ããã¦ãã¾ãåé¡ã¨ãã®ã¬ã¤ã¢ã¦ãããã»ã¹ã®ãããã° - maiyama4's blogã§ããã
ã¿ãªããCompose使ã£ã¦ãã¾ããï¼ ããã§è¨ãComposeã¯docker compose
ã¨ãnerdctl compose
ã¨ãã§å¼ã¹ãã³ã³ããè¤æ°ç«ã¡ä¸ãããã®ãã¨ã§ãã
Docker Composeã¯compose specã¨ãã¦æ¨æºåããã¦ããä»æ§ã®ãªãã¡ã¬ã³ã¹å®è£
ã§ãããä»ã®ã©ã³ã¿ã¤ã ãããComposeã使ããã¨ãã§ãã¾ãããªã®ã§ä»åã¯ã¾ã¨ãã¦Composeã¨å¼ã¶ãã¨ã¨ãã¾ãã
Composeãã¡ã¤ã«ã®è¤æ°æå®
ããªãã¿ã®compose.yaml
ãã¡ã¤ã«ã§ãããComposeå®è¡æã«ãã¡ã¤ã«ãæå®ãããã¨ãã§ãã¾ãããããè¤æ°æå®ãããã¨ãã§ãã¾ãã
ãã¦ãã®ã¨ãã«compose.yamlã¨compose.another.yamlã«åããã¼ã®å¤ãåå¨ããã¨ãã¯ã©ããªãã§ããã*1ã
# compose.yaml services: app: image: nginx:latest # compose.another.yaml services: app: image: ubuntu:latest
ãã®ããã«ãã¦å¼ã³åºãã¦ã¿ã¾ãããã
docker compose config
ã³ãã³ãã使ãã¨ãå®éã«ä½¿ç¨ãããcomposeãã¡ã¤ã«ãåããããã§ãããã£ã¦ã¿ã¾ãããã
$ docker compose -f compose.yaml -f compose.another.yaml config name: ymse services: app: image: ubuntu:latest networks: # èªåä»å default: null networks: # èªåä»å default: name: ymse_default
nginxã¨æå®ãã¦ããimageãubuntuã¨ä¸æ¸ãããã¦ãããã¨ããããã¾ããã
試ãã¦ã¿ãã¨ãã®ã«ã¼ã«ã¯ä»ã«ãenvironmentãªã©ã§ãé©ç¨ããããã¨ããããã¾ãã ãã£ã¦ã¿ã¾ãããã
# compose.yaml services: app: image: nginx:latest environment: foo: '1' bar: '2' # compose.another.yaml services: app: image: ubuntu:latest environment: foo: override
ãããªæãã«yamlãæ¸ãã¦å®è¡ãã¦ã¿ãã
$ docker compose -f compose.yaml -f compose.another.yaml config name: ymse services: app: environment: bar: "2" foo: override image: ubuntu:latest networks: default: null networks: default: name: ymse_default
確ãã«compose.another.yaml
ã§æå®ããservices.app.environment.foo
ã®ã¿ãä¸æ¸ãããã¦ãããã¨ããããã¾ããã
ã¨ãããã¨ãComposeã®ä»æ§ã§ããcompose-specã«è¨è¿°ããã¦ãã¾ãã
ç¡ã§ä¸æ¸ãããã
ãã¦ãã®compose-specã®mergingã®ã»ã¯ã·ã§ã³ã§ããçºãã¦ã¿ãã¨ãç¹å®ã®ãã¼ã®å¤ãresetãããã¨ãã§ããã¿ããã§ãã確ãã«çæ´»ãã¦ããã°ç¹å®ç°å¢ã®ã¿ã§å¤ãã»ããããããã¨ãããã
# https://github.com/compose-spec/compose-spec/blob/e9dc800c027a513254bbf15ee05893a8105a6afb/13-merge.md#reset-value ããå¼ç¨ã # file Aã追è¨ãããªã©ä¸é¨æ¹å¤ã # file A services: app: image: myapp ports: - "8080:80" environment: FOO: BAR # file B services: app: image: myapp ports: !reset [] environment: FOO: !reset null
ä¸æ¸ããããå¤ã®é ã«!reset
ã¨ä»ããã¨ç¡ã§ä¸æ¸ãã§ããããã§ãã
å®éã«ã©ããªcomposeãã¡ã¤ã«ãçæãããã®ãè¦ã¦ã¿ã¾ãããã
$ docker compose -f compose.yaml -f compose.another.yaml config name: ymse services: app: image: myapp networks: default: null networks: default: name: ymse_default
å®éã«portsã¨environmentããªãããããã¦ãããã¨ããããã¾ããã
YAML Tagã§å®ç¾ãããªã»ãã
ãã¦ããããã«!reset
ãé ã«ä»ããã¨ãã¼ã¸ããã¨ãã«ãã¾ããã£ã¦ãããããã¨ç´¹ä»ãã¾ãããããã®!reset
ã®æ£ä½ã¯ãªããªã®ã§ããããã
ããã¯YAMLã®tagã¨å¼ã°ãããã®ã§ãã
YAMLã®ä»æ§ã«ããã£ããã¨æè¨ããã¦ããææ³ã§ã!
1ã¤ã§å§ã¾ãã¿ã°ã¯ã¢ããªã±ã¼ã·ã§ã³åºæã®ãã¼ã«ã«ã¿ã°ã¨å¼ã°ãã¦ãã¾ãã
https://yaml.org/spec/1.2.2/#24-tags https://yaml.org/spec/1.2.2/#3212-tags
ãã¼ã«ã«ã¿ã°ã¯ãã¼ã¹ããã¢ããªã±ã¼ã·ã§ã³å´ã§èªç±ã«æ±ããã¨ãã§ãã¾ãã
ä¾ãã°Rubyã®YAMLãã¼ãµã§ããlibrary yamlã§ã¯ãã¼ã«ã«ã¿ã°ãä»ãããã¨ã«ããããã¼ã¹ãããã¨ã«Rubyã®ã©ã®ã¯ã©ã¹ã§æ±ãããæå®ã§ãã¾ãã
docker/composeãåç §ãã¦ãã compose-spec/compose-go ã®ä¸ã§ãå®éã«YAMLã®ã¿ã°ããã¼ã¹ãã¦resetãªããããªã«ããã³ã¼ããåå¨ãã¦ãã¾ãã
ãã®ã³ã¼ãã®ãããã§ä¸æ¸ããã§ããã®ã§ããã
ã¾ã¨ã
compose-specãçºãã¦ãããè¦ã¤ããããã¾ãç¥ããã¦ããªããããªä»æ§ã«ã¤ãã¦èª¿ã¹ããYAMLã®ã¿ã°ã«æµãçãã¾ããã ç¥ããªãä»æ§ãç¥ããã¨ã¯é¢ç½ãã§ããã
以ä¸ãã¯ã¦ãªã¨ã³ã¸ã㢠- Qiita Advent Calendar 2024 - Qiita13æ¥ç®æ å½ã® id:ymseã§ããã14æ¥ç®ã®æ å½ã¯ id:utgwkk ããã§ã