0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

業務でよく使用するDockerコマンドをまとめる

Last updated at Posted at 2022-06-28

宣伝

自社ブログに自身のDockerコンテナ起動までのハンズオン記事を投稿しました。

業務でよく使用するDockerコマンド集

イメージビルド系

Docker イメージをビルドする

$ docker image build -t [イメージ名] .

コンテナ起動系

コンテナ起動と同時に中に入る

$ docker container run --name [コンテナ名] -it [イメージ名] /bin/bash

削除系

イメージ一括削除

$ docker rmi -f $(docker images -q)

コンテナ一括削除

$ docker container prune

レジストリを移行する時の流れ

$ docker pull [移行元のdockerイメージ]
$ docker tag [移行元のdockerイメージ] [移行先のdockerイメージ]
$ docker push [移行先のdockerイメージ]

上記をシェルスクリプトで自動化する

move-docker-image.sh
set -ex 

FILE_PATH=$1

while read line || [ -n "${line}" ]; do
  src_image=$(echo ${line} | cut -d'' -f 1)
  dst_image=$(echo ${line} | cut -d'' -f 2)
  docker pull $src_image
  docker tag $src_image $dst_image
  docker push $dst_image
done < $FILE_PATH
docker-images.txt
[移行元のdockerイメージ1] [移行先のdockerイメージ1]
[移行元のdockerイメージ2] [移行先のdockerイメージ2]
︙
$ bash move-docker-image.sh docker-images.txt
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?