1
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 3 years have passed since last update.

【Artifactory】Dockerリポジトリの使い方

Posted at

ArtifactoryのDockerリポジトリ

Artifactoryというリポジトリ管理サービスには様々なリポジトリタイプが使用可能ですが、今回はその中の一つであるDockerについて使い方を掲載します。
Dockerとはコンテナ仮想化のオープンソースソフトウェアの一つで、ソフトウェアやサービス単位で管理する事が出来ます。

事前準備

Dockerリポジトリを使用する為に、クライアント側にDockerをインストールする必要があります。
WindowsやMacでDockerを使用する場合はこちらからクライアントソフトをダウンロードします。
CentOS(Linux)では以下のコマンドを実行します。

yum install docker

インストール後に以下のコマンドでDockerを起動します。

systemctl start docker

Dockerの試用準備が完了したので、次はDockerのテスト用イメージ「hello-world」を取得(Pull)します。
取得には以下のコマンドを実行します。

docker pull hello-world

実行後以下のメッセージが表示されていれば完了。
Status: Downloaded newer image for docker.io/hello-world:latest

「hello-world」イメージの取得後、docker imagesコマンドを実行すると、以下の様な結果が表示されます。

REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/hello-world   latest              bf756fb1ae65        12 months ago       13.3 kB

DockerリポジトリへイメージをPush

先程取得した「hello-world」イメージをArtifactory上のDockerリポジトリへPushします。
まずは以下のコマンドを実行し、対象のDockerリポジトリにログインします。

docker login <ArtifactoryのFQDN>

Username:<Artifactoryへのログインユーザー名>
Password:<Artifactoryへのログインパスワード>

ログインしましたら、DockerリポジトリへイメージをPushしますが、その前にPushするイメージにタグを設定します。
コマンドは以下です。

docker tag <対象dockerイメージID> <ArtifactoryのFQDN>/<Dockerリポジトリ名>/<対象dockerイメージ名>:<タグ名>

<対象dockerイメージID>は「docker images」コマンドで表示されたIMAGE IDを入力する。
<対象dockerイメージ名>はPush対象のイメージ名(今回の場合はhello-world)
<タグ名>は任意

タグを付けた後で再度docker imagesを実行すると以下の通りリポジトリが追加されています。

REPOSITORY                                            TAG                 IMAGE ID            CREATED             SIZE
docker.io/hello-world                                 latest              bf756fb1ae65        12 months ago       13.3 kB
<ArtifactoryのFQDN>/<Dockerリポジトリ名>/hello-world   <設定したタグ名>               bf756fb1ae65        12 months ago       13.3 kB

この状態でArtifactoryへpushします。コマンドは以下です。

docker push <ArtifactoryのFQDN>/<Dockerリポジトリ名>/<対象dockerイメージ名>:<設定したタグ名>

上記コマンド実行後に以下の内容が表示されたら完了。
Pushed
<タグ名>: digest: sha256:<省略>

PushしたイメージをPull

先程Pushした「hello-world」イメージをPullします。
その前にクライアント上に残っているイメージを削除します。
イメージを削除するコマンドは以下です。アルファベットと数字の羅列で表記されているイメージIDで指定するという事に注意してください。

docker rmi <イメージID>

※上記コマンドで「hello-world」イメージを削除しようとしたら「Error response from daemon: conflict: unable to delete bf756fb1ae65 (must be forced) - image is referenced in multiple repositories」というエラーが表示されました。
その場合は「-f」オプションを追加して強制削除します。
※強制削除実行前に以下コマンドを実行して念の為削除対象のプロセスが起動されていないか確認します。
docker ps -a

docker imagesを実行してPull対象のイメージが表示されない事を確認しましたら、以下のコマンドからイメージのPullを行います。

docker pull <ArtifactoryのFQDN>/<Dockerリポジトリ名>/<対象dockerイメージ名>:<設定したタグ名>

実行後以下のメッセージが表示されていれば完了。
Status: Downloaded newer image for <ArtifactoryのFQDN>/<Dockerリポジトリ名>/<対象dockerイメージ名>:<設定したタグ名>

docker imagesを実行したら、以下の様な結果が表示されます。

REPOSITORY                                            TAG                 IMAGE ID            CREATED             SIZE
<ArtifactoryのFQDN>/<Dockerリポジトリ名>/<対象dockerイメージ名>   <設定したタグ名>               bf756fb1ae65        12 months ago       13.3 kB

以上でArtifactoryのDockerリポジトリの使い方は完了です。

1
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
1
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?