Recreate and Start Containers with docker-compose up --force-recreate

Tadashi Shigeoka ·  Wed, July 26, 2017

To recreate containers before starting them with docker-compose up, you can achieve this by adding the —force-recreate option.

Docker

During development, after building without cache using docker-compose build —no-cache, running docker-compose up —force-recreate as a precaution should reduce problems where changes aren’t reflected.

docker-compose up Options

使い方: up [オプション] [サービス...]

“Usage: up [options] [services…]

オプション: -d デタッチド・モード: バックグラウンドでコンテナを実行し、新しいコンテナ名を表示 —abort-on-container-exit と同時に使えない —no-color 白黒で画面に表示 —no-deps リンクしたサービスを表示しない —force-recreate 設定やイメージに変更がなくても、コンテナを再作成する —no-recreate と同時に使えません —no-recreate コンテナが既に存在していれば、再作成しない —force-recreate と同時に使えない —no-build イメージが見つからなくても構築しない —build コンテナを開始前にイメージを構築する —abort-on-container-exit コンテナが1つでも停止したら全てのコンテナを停止 -d と同時に使えない -t, —timeout TIMEOUT アタッチしている、あるいは既に実行中のコンテナを 停止する時のタイムアウト秒数を指定 (デフォルト:10 ) —remove-orphans Compose ファイルで定義されていないサービス用のコンテナを削除

Options: -d Detached mode: run containers in the background and display new container names Cannot be used with —abort-on-container-exit —no-color Display in black and white —no-deps Don’t show linked services —force-recreate Recreate containers even if configuration or images haven’t changed Cannot be used with —no-recreate —no-recreate Don’t recreate containers if they already exist Cannot be used with —force-recreate —no-build Don’t build images even if they can’t be found —build Build images before starting containers —abort-on-container-exit Stop all containers if any container stops Cannot be used with -d -t, —timeout TIMEOUT Specify timeout seconds when stopping attached or already running containers (default: 10) —remove-orphans Remove containers for services not defined in the Compose file”

もしも Compose で処理時、強制的に全てのコンテナを停止・再作成するには —force-recreate フラグを使います。

“To forcibly stop and recreate all containers when processing with Compose, use the —force-recreate flag.”

If there are many target containers, recreating and starting containers takes time, so an approach like docker-compose up —force-recreate targetContainerName to recreate only specific containers would save time.

Reference Information

That’s all from the Gemba.