これができれば便利ですdocker-compose build service1 service2 --no-cache
構文がdocker-compose build --no-cache service1 service2
これを探していました!!
これが私の作成スタックを再構築するためのクリーンな方法です
cd(作成DIRへ)
docker-compose rm --all &&
docker-compose pull &&
docker-compose build --no-cache &&
docker-compose up -d --force-recreate &&
わかる? ここでベストプラクティスを探しています:)
+1
--force-recreateは必要ですか?
+1
--force-recreate
が最良の選択だと思います
--force-recreate
は、すべてのコンテナが削除されたばかりなので不要です。
_すべて_をクリアしたい場合は、ボリュームとネットワークも削除できるため、 down
はrm
よりも優れています。
$ docker-compose down -h
Stops containers and removes containers, networks, volumes, and images
created by `up`.
By default, the only things removed are:
- Containers for services defined in the Compose file
- Networks defined in the `networks` section of the Compose file
- The default network, if one is used
Networks and volumes defined as `external` are never removed.
Usage: down [options]
Options:
--rmi type Remove images. Type must be one of:
'all': Remove all images used by any service.
'local': Remove only images that don't have a custom tag
set by the `image` field.
-v, --volumes Remove named volumes declared in the `volumes` section
of the Compose file and anonymous volumes
attached to containers.
--remove-orphans Remove containers for services not defined in the
Compose file
私はこれを3か月間使用していますが、私のニーズにはしっかりと合っています。
削除したくない:ネットワーク、ボリューム、イメージ
echo && echo "PikWi says: docker-compose stop" && \
docker-compose stop && \
echo "PikWi says: docker-compose rm ..." && \
docker-compose rm -f --all && \
echo "PikWi says: docker-compose pull" && \
docker-compose pull && \
echo "PikWi says: docker-compose build ..." && \
docker-compose build --no-cache && \
echo "PikWi says: docker-compose up ..." && \
docker-compose up -d --force-recreate --remove-orphans
もっと短いものやもっときれいなものを使ってよかったです。 私はすべてベストプラクティスです:)
乾杯!
--no-cacheが機能しません....代替手段は何ですか--force-rebuildは引き続きキャッシュを使用します:(
@julianfrank --no-cache does not work
の意味がわかりませんが、おそらく次のように実行しますdocker-compose build SERVICE_NAME --no-cache
実際にdocker-compose build --no-cache SERVICE_NAME
でなければならないのはいつですか?
ビルドされるさまざまなサービス間で手順が同じである場合でも、スクリプトの前半で作成されたコンテナのキャッシュを使用します...キャッシュを使用して順序を変更し、キャッシュを強制的にスキップする場合は、同じ手順を使用する代わりの方法を考案しました利用方法...
キャッシュに夢中になり、代わりにキャッシュを使用しない場合は、dockerファイルに新しいコマンドを挿入して、キャッシュレイヤーの更新を強制します。サムズアップを送信します。dockerでのキャッシュ処理にはリファクタリングが必要です...または実際にキャッシュレイヤーをクリーンアップします。
確かに、それは動作しません...
サービスのDockerfileにすべての変更を加えることができ、 docker-compose build --no-cache
には反映されません。
docker-compose up -d --build --no-deps web
は、docker-compose.ymlで「web」という名前のサービスのコンテナーを再構築します。 再構築が完了すると、指定されたコンテナが再起動します。
--no-deps
は、コマンドで指定されたサービスの名前に再構築を制限します。
さらに、ファイルをコンテナにコピーしていて、コピー先のファイルの1つ(requirements.txtなど)が変更されている場合、このコマンドはコンテナを再構築します。
ご参考までにdocker-compose up --force-recreate --build
upコマンドには明らかに--no-cacheオプションはありません
force-recreateはこのオプションを使用していないようです。 私が間違っている場合は私を訂正してください!
したがって、最善のアプローチは私がこれを行うことです...
コンテナとイメージを削除します>ビルドキャッシュなしでイメージをビルドします>docker-デタッチして構成します>ログを追跡します(ログからctrl+c
を取得できます)
docker-compose build --force-rm --no-cache && docker-compose up --detach && docker-compose logs -f
ウィンドウズ:
docker-compose build --force-rm --no-cache ; docker-compose up --detach ; docker-compose logs -f
最も参考になるコメント
構文が
docker-compose build --no-cache service1 service2