背景
この前の記事では、docker commitの操作で新イメージを作成しました。
今回はこのローカルのイメージをdockerhub に公開してみます。
公開したら、世界中の人々から見えるし、ダウンロードも出来ますね。
前提条件:docker hubのアカウントを持っている。
アカウントが無料です、メールアドレスがあれば、作れるはず。
1. 準備
1-1. ubuntuコンテナにvimをインストール
[root@localhost home]# docker run -it --name=ubuntu-1 ubuntu bash
root@70890083f470:/# apt-get update
apt-get -y install vim
1-2. dokcer commitで新イメージmyubuntuを作成
root@70890083f470:/# [root@localhost home]# //Crtl + p + qでコンテナを出る
[root@localhost home]# docker ps | grep ubuntu //起動したubuntuコンテナのステータスを確認
70890083f470 ubuntu "bash" About a minute ago Up About a minute ubuntu-1
[root@localhost home]#
[root@localhost home]# docker commit -m="add vim to commit" -a=tin ubuntu-1 myubuntu
sha256:b867113f967004306c3879cbac30a9c76ef0d558e17c23d21f3f0e2a47d9d3dd
[root@localhost home]#
[root@localhost home]# docker images | grep ubuntu
myubuntu latest b867113f9670 48 seconds ago 179MB //新イメージ
ubuntu latest 58db3edaf2be 5 weeks ago 77.8MB
[root@localhost home]#
2. ローカルのイメージmyubuntuを dockerhub に公開
2-1. dockerhubリポジトリに自分のリポジトリを作る
出来たリポジトリ
2-2. docker tag
でイメージに別名(自分のリポジトリに合わせる)を付ける
※イメージ名は元々自分のリポジトリ名に一致する場合、docker tagを実施しなくても良い
[root@localhost home]# docker tag myubuntu tinkouka/myubuntu:2.0
[root@localhost home]#
[root@localhost home]# docker images | grep ubuntu
tinkouka/myubuntu 2.0 b867113f9670 16 minutes ago 179MB
myubuntu latest b867113f9670 16 minutes ago 179MB
ubuntu latest 58db3edaf2be 5 weeks ago 77.8MB
[root@localhost home]#
2-3. docker login
でログイン
[root@localhost home]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: tinkouka
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@localhost home]#
2-4. docker push
dockerhub にプッシュして公開
[root@localhost home]# docker push tinkouka/myubuntu:2.0
The push refers to repository [docker.io/tinkouka/myubuntu]
5f8550288423: Pushed
c5ff2d88f679: Mounted from library/tomcat
2.0: digest: sha256:c142faad41ec8e5d761bdc115e66886dbb11abb9f235dfa9b6c952cefa2bb0f7 size: 741
dockerhubで確認
コメント欄