docker-compose dynamic volume names for replicas

オープン
#9,026 コメント 10 件 リアクション 7 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

  • #14188 @NAVEENKUMARKR777 による — マージされずにクローズ

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
技術スタック
docker, docker-compose, yaml

調査の方向性

まず、提供された docker-compose.yml のスニペットと報告されている docker-compose up configsvr0 コマンドを使用して、Docker Compose v2.2.1 で文書化された 2 つの例を再現します。サービスのレプリカとボリューム名に対する Compose の処理を確認します。完了条件は、サービスまたはボリュームのエントリをコピーしなくても、1 つの宣言されたボリュームからレプリカごとの有効な名前を生成できることです。

索引モデルが issue の本文から書いたものです。

説明

kind/feature

moved over from https://github.com/moby/moby/issues/43079

Tried some of the "solutions" from this thread and stackoverflow. No swarm, node or other hosts at all. Just trying to get it to work locally first without starting containers around docker-compose. Main idea is to get rid of these copies and just use replicas:

  configsvr0:
    image: mongo
    command: mongod --configsvr --replSet configsvr --port 27017 --dbpath /data/db --keyFile /data/keyfile
    volumes:
      - configsvr0:/data/db
      - ./keyfile:/data/keyfile:ro
  configsvr1:
    image: mongo
    command: mongod --configsvr --replSet configsvr --port 27017 --dbpath /data/db --keyFile /data/keyfile
    volumes:
      - configsvr1:/data/db
      - ./keyfile:/data/keyfile:ro
  configsvr2:
    image: mongo
    command: mongod --configsvr --replSet configsvr --port 27017 --dbpath /data/db --keyFile /data/keyfile
    volumes:
      - configsvr2:/data/db
      - ./keyfile:/data/keyfile:ro

volumes:
  configsvr0:
  configsvr1:
  configsvr2:

See the difference? It's just counting up on the volume name...

It would be great to just have something like this:

  configsvr0:
    image: mongo
    command: mongod --configsvr --replSet configsvr --port 27017 --dbpath /data/db --keyFile /data/keyfile
    volumes:
      - configsvr:/data/db
      - ./keyfile:/data/keyfile:ro

volumes:
  configsvr:
    name: 'configsvr-{{.Task.Slot}}'

Tried this (see below) but it didn't work.

Note: Below I only copied small junks from my yml that I thought are important for this.

test 1 - volume name

would require to add entries under volumes so that's not really dynamic - but I gave it a try:

    volumes:
      - "configsvr{{.Task.Slot}}:/data/db"
➜  msc git:(develop) ✗ docker-compose up configsvr0
service "configsvr0" refers to undefined volume configsvr{{.Task.Slot}}: invalid compose project
test2 - dynamic name with task slot

that would be dynamic but still doesn't work though it was accepted in stackoverflow. That's actually my sample from top.

    volumes:
      - configsvr:/data/db

volumes:
  configsvr:
    name: 'configsvr-{{.Task.Slot}}'
➜  msc git:(develop) ✗ docker-compose up configsvr0
[+] Running 0/0
 ⠿ Volume "configsvr-{{.Task.Slot}}"  Error                                                                                                                                                          0.0s
Error response from daemon: create configsvr-{{.Task.Slot}}: "configsvr-{{.Task.Slot}}" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path
my env

mac monteray with docker desktop.

➜  msc git:(develop) ✗ docker -v
Docker version 20.10.11, build dea9396
➜  msc git:(develop) ✗ docker-compose -v
Docker Compose version v2.2.1

docker-compose.yml version: 3.9
主要言語
Go
スター
38.9k
フォーク
6k
平均マージ
2日 22時間
マージ済み PR(30日)
81

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

docker/compose のほかの issue

docker/compose の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。