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 1 year has passed since last update.

ただただ初心者がDockerHubを触れてみるだけ

Last updated at Posted at 2023-01-04

Dockerイメージを手元に置かずに、Dockerのレジストリに置くことで
どんな環境でも同じコンテナを作ることができるらしいので
そんな素敵な環境をただただ試してみた
(今回もOracle CloudのAlways Freeリソースを使います!無料ってすてき!)

注意
座学しないで感覚的にやったことをただただ書いていった記事なので、内容はあまり参考にしない方が良いと思います。。。
(なら公開するな

dockerHubの環境を整える

アカウントを作る

まず、Docker Hubのメイン画面からアカウントを作る
https://hub.docker.com/signup
image.png

とりあえず一旦Personalプランを選ぶ
image.png

CLIからログインする

docker loginコマンドで、さっき作ったアカウント情報を入力する
ログインはできたらしい

[opc@docker ~]$ 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: nephken
Password: 
WARNING! Your password will be stored unencrypted in /home/opc/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

Dockerイメージをアップロードする

別記事で作ったDockerイメージをアップロードして、別サーバで利用できるか試してみる

  • パブリックなリポジトリなので、個人的な情報はイメージ上に乗せないよう注意
  • アップロード時は、[username]/で始まらないといけないらしい

どうせ何かエラー起きると思うので何はともあれやってみた。
まずは本当に名前制限があるのか検証、アクセス権限的な理由ではじかれた

[root@docker ~]# docker images
REPOSITORY           TAG       IMAGE ID       CREATED       SIZE
world-apache-image   latest    132e9e558d01   5 days ago    192MB
helloworld-apache    latest    d6a8916c3b5d   5 days ago    192MB
httpd                2.4       6c064f9f5f14   13 days ago   139MB
httpd                latest    6c064f9f5f14   13 days ago   139MB
[root@docker ~]# docker push world-apache-image
Using default tag: latest
The push refers to repository [docker.io/library/world-apache-image]
207303382b22: Preparing 
762aa0d5eff8: Preparing 
ddb4a47613a2: Preparing 
81bb07f7f1f6: Preparing 
69710c8f06c1: Preparing 
67dbd8927db4: Waiting 
4ca5bcf319c0: Waiting 
denied: requested access to the resource is denied

名前の制限のせいなのか確かめるために、それっぽい名前でDockerイメージを作って再検証
今度はうまくプッシュできたっぽい
単純にどのアカウントのリポジトリにアップロードするのかわからないよ!って感じ?

[root@docker ~]# docker build -t nephken/world-is-mine ./
Sending build context to Docker daemon  23.04kB
Step 1/3 : FROM httpd:2.4
 ---> 6c064f9f5f14
Step 2/3 : RUN apt-get update && apt-get -y install vim
 ---> Using cache
 ---> df441ce9dcb6
Step 3/3 : RUN mv /usr/local/apache2/htdocs/index.html /usr/local/apache2/htdocs/index.html_org && echo 'HelloWorld' > /usr/local/apache2/htdocs/index.html
 ---> Using cache
 ---> 132e9e558d01
Successfully built 132e9e558d01
Successfully tagged nephken/world-is-mine:latest

[root@docker ~]# docker push nephken/world-is-mine
Using default tag: latest
The push refers to repository [docker.io/nephken/world-is-mine]
207303382b22: Pushed 
762aa0d5eff8: Pushed 
ddb4a47613a2: Pushed 
81bb07f7f1f6: Pushed 
69710c8f06c1: Pushed 
67dbd8927db4: Pushed 
4ca5bcf319c0: Pushed 
latest: digest: sha256:81adb94c4a2dd42a5bd5c16ed8b0f5a06751b888edf129739597cc837ff71ea1 size: 1785

dockerhub内で検索してみたらアップロードされたDockerイメージを発見
image.png

補足

意図的にリポジトリ作れないの???
って思って、ページ内をいろいろ見てみたらやっぱり手動で作れそうだった。
push時にnephken/って付けたことで、自動的にそのアカウントでリポジトリを作ってくれたみたい。
一つだけならプライベートなリポジトリも作れそうだから、これも試してみたいけどあとで。
image.png

別サーバでDockerイメージをpullしてコンテナ化する

たまたま作ってた海外リージョンのサーバから、dockerイメージをpullして立ち上げてみる
意外とすんなりpullできた
 ※pullはdocker login不要
 ※pull制限がある模様

### まだ何もないDockerイメージ
[root@ashburn-docker ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

### pull
[root@ashburn-docker ~]# docker pull nephken/world-is-mine
Using default tag: latest
latest: Pulling from nephken/world-is-mine
4b7f5b2a3113: Pull complete 
fac45e5a15ef: Pull complete 
60db67158dbf: Pull complete 
b89f66e6e64a: Pull complete 
ef4f55b91ed7: Pull complete 
8a88d4fa0881: Pull complete 
be15c0cfd342: Pull complete 
Digest: sha256:81adb94c4a2dd42a5bd5c16ed8b0f5a06751b888edf129739597cc837ff71ea1
Status: Downloaded newer image for nephken/world-is-mine:latest
docker.io/nephken/world-is-mine:latest

### pullされたDockerイメージ
[root@ashburn-docker ~]# docker images
REPOSITORY              TAG       IMAGE ID       CREATED      SIZE
nephken/world-is-mine   latest    132e9e558d01   5 days ago   192MB

あとは立ち上げてみる!
プラットフォームが違うよ〜というエラーが。。。

[root@ashburn-docker ~]# docker run --name ashburn-apache -i -t -d -p 8080:80 nephken/world-is-mine
WARNING: The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested
d4af378fafad09fe18ebf8c92d90da4a67af4c2e74c154aadd6be563b7ae323b

いろいろ試したけど、
pushしたサーバとpullしたサーバでCPUが違うからなのか、上手いこと起動ができず。。。。
プラットフォーム問題があるらしい。

[root@ashburn-docker ~]# docker run -it nephken/world-is-mine
WARNING: The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested
exec /usr/local/bin/httpd-foreground: exec format error

上の問題の解決をしたいところだけど、動作確認をしたいだけなので一旦置いておく
プラットフォームを揃えてやってみたら難なく成功

[root@ashburn-docker-2 ~]# docker run --name ashburn-apache -i -t -d -p 8080:80 nephken/world-is-mine
8825fde2678978e6f10d94b31f76a282c7799872ad83ef2a14d0ae7a12fceacc

無事コンテナ起動!
image.png

まとめと疑問

  • DockerHubを使うことでDockerイメージをリポジトリで管理することができた
    • ローカルでイメージ管理もいいけど、別環境でも同じコンテナ環境を立てられるのはいいね
    • DockerFileはGitHubで管理が良い気がする
  • 無料アカウントだとパブリックに公開されてしまうので、個人情報の取り扱いには注意
    • アップロードして数時間で5人くらいにダウンロードされてた。。。こわ。。
  • ホストサーバ(PC)のCPUに依存する場合があるのでそこらへんを理解していかねば
    • CPUって各々のPCで違ってくるはずだから、そこらへんってどうすればいいんだろう?
  • やったあとにちゃんとした記事を読むと理解が深まる
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?