hello-worldのコンテナを稼働させる
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:6f744a2005b12a704d2608d8070a494ad1145636eeb74a570c56b94d94ccdbfc
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/
docker run(コンテナの実行)
docker runコマンドはローカル環境に取得済みのイメージを基に新たなコンテナを作成し、それを実行します。
docker run --name="コンテナ名" hello-world
--nameオプションを指定すると、任意でコンテナ名を指定することができます。
docker ps(コンテナの一覧表示)
$ docker ps -a
docker ps コマンドに -a オプションを指定すると、実行されたコンテナの情報を確認できます。
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5daf7bdf28be hello-world "/hello" 45 minutes ago Exited (0) 45 minutes ago pensive_shannon
docker start(コンテナの再実行)
$ docker start -a pensive_shannon
docker start -a "コンテナ名"で停止中のコンテナの再実行をすることができます。
docker rm(コンテナの削除)
$ docker rm pensive_shannon
docker rm "コンテナ名"でコンテナを削除することができます
全てのコンテナを削除したい場合は
$ docker rm $(docker ps -qa)
fish shellの場合は
$ docker rm (docker ps -qa)
dokcer images(イメージ一覧表示)
$ docker images
取得したイメージの一覧を表示します。
docker rmi(イメージの削除)
$ docker rmi hello-world
Webサーバーを稼働させてみる
docker search コマンドを使用してDockerHubからhttpdを検索
$ docker search httpd
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
httpd The Apache HTTP Server Project 2488 [OK]
centos/httpd 23 [OK]
centos/httpd-24-centos7 Platform for running Apache httpd 2.4 or bui… 22
armhf/httpd The Apache HTTP Server Project 8
lolhens/httpd Apache httpd 2 Server 2 [OK]
polinux/httpd-php Apache with PHP in Docker (Supervisor, CentO… 2 [OK]
salim1983hoop/httpd24 Dockerfile running apache config 2 [OK]
rgielen/httpd-image-simple Docker image for simple Apache httpd based o… 1 [OK]
lead4good/httpd-fpm httpd server which connects via fcgi proxy h… 1 [OK]
interlutions/httpd httpd docker image with debian-based config … 0 [OK]
dockerpinata/httpd 0
trollin/httpd 0
manasip/httpd 0
izdock/httpd Production ready Apache HTTPD Web Server + m… 0
amd64/httpd The Apache HTTP Server Project 0
itsziget/httpd24 Extended HTTPD Docker image based on the off… 0 [OK]
solsson/httpd-openidc mod_auth_openidc on official httpd image, ve… 0 [OK]
buzzardev/httpd Based on the official httpd image 0 [OK]
manageiq/httpd_configmap_generator Httpd Configmap Generator 0 [OK]
appertly/httpd Customized Apache HTTPD that uses a PHP-FPM … 0 [OK]
tugboatqa/httpd The Apache HTTP Server Project 0
ppc64le/httpd The Apache HTTP Server Project 0
publici/httpd httpd:latest 0 [OK]
manageiq/httpd Container with httpd, built on CentOS for Ma… 0 [OK]
alvistack/httpd Docker Image Packaging for Apache 0 [OK]
NAMEがリポジトリ名となっています。
今回はhttpdを利用してみます。
https://registry.hub.docker.com/v2/repositories/library/httpd/tags にアクセスするとどんなタグ名のイメージが存在するのかを調べることができます。
Apache HTTP Serverのバージョンに対応したタグ名がつけられているので
タグ名を指定して
dokcer runでイメージの取得とコンテナの作成・実行を行います。
$ docker run -d -p 8080:80 httpd:latest
-dオプションを指定することでプロセスをバックグラウンドで実行
-pでポートを指定しています。
http://localhost:8080
にアクセスすることで It works!と表示されるページがひらけば成功です。