0
0

More than 3 years have passed since last update.

【初学者による】Dockerに初めて触るぞ! $ docker run hello-world まで

Last updated at Posted at 2021-05-01

$ docker run hello-world
初めてこのコマンドを打つまでの解説

Dockerに必要なもの

  • Dockerコンテナ
  • Dockerイメージ
  • Dockerfile

Dockerコンテナとは?

実行環境
このDockerコンテナの中でOSとかプログラミング言語とかが動くぞ

Dockerイメージとは?

Dockerコンテナを起動させるためのベース
アプリのコードやOSの情報などをひとまとめにしたもの

DVDのリッピングなどをしたことがある人は、.iso というファイルを見たことがあるのでは。
あれも映像とか音声がひとまとまりになってるでしょ?あれみたいなやつ

DockerイメージからDockerコンテナが作られそして起動する

ということを覚えておこう

Dockerfileとは

Dockerイメージの構成情報を記述するファイル

$ docker run hello-world は何をしてんのさ

Docker童貞の方々は、導入後とりあえずこのコマンドを打っていることでしょう

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

なにやらいっぱい表示されていますが、要は
"hello-world"というイメージをもとにコンテナを作成、そして起動したということ。
そもそもこのhello-worldは、
「Hello from Docker! This message shows that your installation appears to be working correctly.」というメッセージを表示するだけのイメージ。
なのでコンテナは自動的に停止するぞ

細かく見ていくと...

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer image for hello-world:latest

これは、「君のパソコン内にhello-worldというイメージは見当たんない!
だから公式のライブラリ(Docker Hub)からイメージをダウンロードするぞ!そして完了したぞ!」
という意味

$ docker run 〇〇 とするだけで、
Dockerイメージをすでに持ってれば起動してくれるし、
無くても「ねーよそんなもん」と言うだけでなく気を効かせてDocker Hubまで見に行ってくれるスゴイ奴

もちろん持ってもいない、Docker Hubにも存在しないコンテナ名を入れても無駄だぞ

$ docker run sonzaishimasenn
Unable to find image 'sonzaishimasenn:latest' locally
docker: Error response from daemon: pull access denied for sonzaishimasenn, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.
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