3
1

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

Docker入門4: 実際にDocker コンテナを建ててみる

Last updated at Posted at 2016-12-01

前回は Docker 使う際の流れを紹介しました。
今回は、 docker の公式ドキュメントのチュートリアルに従い、実際に docker コンテナを建ててみます。

前置き

Dockerについてまだあまり知らないですが、せっかくなので他の人と共有できるようにアウトプットしてみます。
ツッコミ大歓迎です、どんどんおねがいします。

hello-world

早速、公式イメージの hello-world を使って、 docker コンテナを建ててみます!

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete 
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
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.
 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 Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

どうでしょうか?
多少の違いはあれど、似たような表示が出てくるでしょうか?

この docker run hello-world というコマンドは、 hello-world というイメージからコンテナを作るコマンドです。

初めての場合は、ローカルに hello-world イメージがないため、自動的に docker hub からイメージを pull しています。

ubuntu

もう少しいろいろいじってみたくなってきませんか?
次は OS のイメージからコンテナを作り、 bash を起動してみましょう。

$ docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
af49a5ceb2a5: Pull complete 
8f9757b472e7: Pull complete 
e931b117db38: Pull complete 
47b5e16c0811: Pull complete 
9332eaf1a55b: Pull complete 
Digest: sha256:3b64c309deae7ab0f7dbdd42b6b326261ccd6261da5d88396439353162703fb5
Status: Downloaded newer image for ubuntu:latest
root@36e7d869592b:/#

これにより ubuntu のイメージからコンテナを作り、コンテナにアタッチしました。
試しに ls コマンドを実行します。

root@36e7d869592b:/# ls
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

終了しましょう。

root@36e7d869592b:/# exit

docker ps

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                     NAMES
36e7d869592b        ubuntu              "bash"                   37 minutes ago      Exited (0) 9 seconds ago                              hopeful_ardinghelli
77f839d7c182        hello-world         "/hello"                 47 minutes ago      Exited (0) 47 minutes ago                             suspicious_lichterman
  • docker ps -a: すべてのコンテナを表示します。

まとめ

どうでしょうか?
少しはイメージがつかめてきたでしょうか?

次回

次回は docker hub を使ったコンテナの作り方を解説します。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?