docker image pull(イメージダウンロード)
docker image pull [options] イメージ名[:タグ名]
例:CentOSのバージョン7(タグ名:7)をダウンロードする
CentOSイメージ取得
docker@LesPaul:~$ docker image pull centos:7
7: Pulling from library/centos
256b176beaff: Pull complete
Digest: sha256:6f6d986d425aeabdc3a02cb61c02abb2e78e57357e92417d6d58332856024faf
Status: Downloaded newer image for centos:7
※タグ名を省略すると最新版(latest)を取得する
CentOSの全てのタグのイメージ取得
「-a」オプションを指定すると全てのタグを取得可能。
「-a」オプションを指定する場合、Dockerイメージ名にタグを指定できないので注意。
$ docker image pull -a centos
Jenkinsイメージ取得
docker@LesPaul:~$ docker image pull jenkins:latest
latest: Pulling from library/jenkins
55cbf04beb70: Pull complete
1607093a898c: Pull complete
9a8ea045c926: Pull complete
d4eee24d4dac: Pull complete
c58988e753d7: Pull complete
794a04897db9: Pull complete
70fcfa476f73: Pull complete
0539c80a02be: Pull complete
54fefc6dcf80: Pull complete
911bc90e47a8: Pull complete
38430d93efed: Pull complete
7e46ccda148a: Pull complete
c0cbcb5ac747: Pull complete
35ade7a86a8e: Pull complete
aa433a6a56b1: Pull complete
841c1dd38d62: Pull complete
b865dcb08714: Pull complete
5a3779030005: Pull complete
12b47c68955c: Pull complete
1322ea3e7bfd: Pull complete
Digest: sha256:eeb4850eb65f2d92500e421b430ed1ec58a7ac909e91f518926e02473904f668
Status: Downloaded newer image for jenkins:latest
docker image ls(イメージ一覧表示)
docker image ls [options][リポジトリ[:タグ名]]
Options |
Description |
-all,-a |
すべてのイメージを表示 |
--digests |
ダイジェストを表示するかどうか |
--no-trunc |
結果をすべて表示 |
--quiet,-q |
DockerイメージIDのみ表示 |
イメージ一覧表示
docker@LesPaul:~$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest be1f31be9a87 6 days ago 109MB
ubuntu latest cd6d8154f1e1 4 weeks ago 84.1MB
centos 7 5182e96772bf 2 months ago 200MB
docker image lsコマンド結果
Item |
Description |
REPOSITORY |
イメージ名 |
TAG |
イメージタグ名 |
IMAGE ID |
イメージID |
CREATED |
作成日 |
SIZE |
イメージサイズ |
docker image inspect(イメージ詳細確認)
イメージ詳細表示
docker@LesPaul:~$ docker image inspect centos:7
[
{
"Id": "sha256:5182e96772bf11f4b912658e265dfe0db8bd314475443b6434ea708784192892", <---①
"RepoTags": [
"centos:7",
"centos:centos7",
"centos:latest"
],
"RepoDigests": [
"centos@sha256:6f6d986d425aeabdc3a02cb61c02abb2e78e57357e92417d6d58332856024faf"
],
"Parent": "",
"Comment": "",
"Created": "2018-08-06T19:21:48.235227329Z", <---②
"Container": "d60ffc9ddd12462af4bdcdbe45b74f3b3f99b46607ada80c3ed877b7def84250",
"ContainerConfig": {
"Hostname": "d60ffc9ddd12",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"/bin/bash\"]"
],
"ArgsEscaped": true,
"Image": "sha256:748eacc0f236df2fc9ba87c4d76a66cb10742120387e99e2acdb9454915c841d",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20180804",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS"
}
},
"DockerVersion": "17.06.2-ce", <---③
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"ArgsEscaped": true,
"Image": "sha256:748eacc0f236df2fc9ba87c4d76a66cb10742120387e99e2acdb9454915c841d",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20180804",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS"
}
},
"Architecture": "amd64", <---④
"Os": "linux",
"Size": 199723824,
"VirtualSize": 199723824,
"GraphDriver": {
"Data": {
"MergedDir": "/var/lib/docker/overlay2/04d9e945bc770af8408522c65e76a6db03eda99c0c8ab5248366d208b5a89954/merged",
"UpperDir": "/var/lib/docker/overlay2/04d9e945bc770af8408522c65e76a6db03eda99c0c8ab5248366d208b5a89954/diff",
"WorkDir": "/var/lib/docker/overlay2/04d9e945bc770af8408522c65e76a6db03eda99c0c8ab5248366d208b5a89954/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:1d31b5806ba40b5f67bde96f18a181668348934a44c9253b420d5f04cfb4e37a"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
①イメージID
②作成日
③Dockerバージョン
④CPUのアーキテクチャ
出力結果はJSON(JavaScript Object Notation)形式。
OS情報取得
docker@LesPaul:~$ docker image inspect --format="{{.Os}}" centos:7
linux
image情報取得
docker@LesPaul:~$ docker image inspect centos --format="{{.ContainerConfig.Image}}"
sha256:748eacc0f236df2fc9ba87c4d76a66cb10742120387e99e2acdb9454915c841d
docker image tag(イメージタグ設定)
Docker Hubに作成したイメージを登録するには以下の規則でイメージにユーザー名を付与します。
<Docker Hubのユーザー名>/イメージ名:[タグ名]
イメージへのタグ設定
例:nginxという名称のイメージに対し、ユーザー名がundercoverでコンテナ名がwebserverでタグにバージョン情報である1.0というタグを付与する。
docker@LesPaul:~$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest be1f31be9a87 6 days ago 109MB
ubuntu latest cd6d8154f1e1 4 weeks ago 84.1MB
centos 6.6 48ac30562192 2 months ago 203MB
docker@LesPaul:~$ docker image tag nginx undercover/webserver:1.0
docker@LesPaul:~$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest be1f31be9a87 6 days ago 109MB
undercover/webserver 1.0 be1f31be9a87 6 days ago 109MB
ubuntu latest cd6d8154f1e1 4 weeks ago 84.1MB
centos 6.6 48ac30562192 2 months ago 203MB
docker search(イメージ検索)
Docker Hubに公開されているイメージを検索する。
docker search [options] keyword
Options |
Description |
--no-trunc |
結果をすべて表示 |
--limit |
n件の検索結果を表示 |
--filter=stars=n |
お気に入りの数(n以上)の指定 |
Docker Hubに公開されているイメージ検索
docker@LesPaul:~$ docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 9823 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1425 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 619 [OK]
jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as p… 423 [OK]
kong Open-source Microservice & API Management la… 230 [OK]
webdevops/php-nginx Nginx with PHP-FPM 113 [OK]
kitematic/hello-world-nginx A light-weight nginx container that demonstr… 111
zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi… 72 [OK]
bitnami/nginx Bitnami nginx Docker Image 58 [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 45 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 40
tobi312/rpi-nginx NGINX on Raspberry Pi / armhf 22 [OK]
blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 12 [OK]
wodby/drupal-nginx Nginx for Drupal container image 11 [OK]
nginxdemos/hello NGINX webserver that serves a simple page co… 8 [OK]
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 8
webdevops/nginx Nginx container 8 [OK]
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 5
1science/nginx Nginx Docker images that include Consul Temp… 4 [OK]
behance/docker-nginx Provides base OS, patches and stable nginx f… 3 [OK]
pebbletech/nginx-proxy nginx-proxy sets up a container running ngin… 2 [OK]
toccoag/openshift-nginx Nginx reverse proxy for Nice running on same… 1 [OK]
travix/nginx NGinx reverse proxy 1 [OK]
mailu/nginx Mailu nginx frontend 1 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 0 [OK]
docker searchコマンド結果
Item |
Description |
NAME |
イメージ名 |
DESCRIPTION |
イメージの説明 |
STARS |
お気に入りの数 |
OFFICIAL |
公式イメージか否か |
AUTOMATED |
Dockerfileを基に自動生成されたイメージか否か |
人気イメージの検索
例:STARSの件数が1000件以上のイメージの検索
docker@LesPaul:~$ docker search --filter=stars=1000 nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 9823 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1425 [OK]
n件の検索
例:mysqlを検索キーワードとして表示件数(5件)を制限して検索
docker@LesPaul:~$ docker search --limit 5 mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 7099 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 517 [OK]
zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 133 [OK]
mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 33
circleci/mysql MySQL is a widely used, open-source relation… 7
docker image rm(イメージの削除)
docker image rm [options] イメージ名 [イメージ名]
Options |
Description |
--force,-f |
イメージを強制的に削除 |
--no-prun |
中間イメージを削除しない |
イメージの削除
例:REPOSITORYがnginxのイメージを削除する。
docker@LesPaul:~$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest be1f31be9a87 6 days ago 109MB
undercover/webserver 1.0 be1f31be9a87 6 days ago 109MB
ubuntu latest cd6d8154f1e1 4 weeks ago 84.1MB
jenkins latest cd14cecfdb3a 2 months ago 696MB
docker@LesPaul:~$ docker image rm nginx
Untagged: nginx:latest
Untagged: nginx@sha256:9ad0746d8f2ea6df3a17ba89eca40b48c47066dfab55a75e08e2b70fc80d929e
docker@LesPaul:~$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
undercover/webserver 1.0 be1f31be9a87 6 days ago 109MB
ubuntu latest cd6d8154f1e1 4 weeks ago 84.1MB
jenkins latest cd14cecfdb3a 2 months ago 696MB
未使用のDockerイメージを削除するときは、Docker image pruneコマンドを使用する。
docker image prune [options]
Options |
Description |
--all,-a |
使用していないイメージをすべて削除 |
--force,-f |
イメージを強制的に削除 |
docker login(Docker Hubログイン)
※アカウントが無い場合は、本セクションの実施前に下部「Appendix」を参考に登録を済ませてください。
docker login [options] [server]
Options |
Description |
--password,-p |
パスワード |
--username,-u |
ユーザー名 |
docker@LesPaul:~$ 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: 登録したユーザー名
Password: 登録したパスワード
WARNING! Your password will be stored unencrypted in /home/docker/.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@LesPaul:~$ docker login -u <ユーザー名> -p <パスワード>
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /home/docker/.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 image push(イメージアップロード)
docker image push イメージ名[:タグ名]
Docker Hubにアップするイメージは以下のようにします。
<Docker Hubユーザー名>/イメージ名:[タグ名]
イメージアップロード
※事前にDocker Hubにログインしている必要があります。
docker@LesPaul:~$ docker image push undercoverism/webserver:1.0
The push refers to repository [docker.io/undercoverism/webserver]
92b86b4e7957: Mounted from library/nginx
94ad191a291b: Mounted from library/nginx
8b15606a9e3e: Mounted from library/nginx
1.0: digest: sha256:204a9a8e65061b10b92ad361dd6f406248404fe60efd5d6a8f2595f18bb37aad size: 948
docker logout(Docker Hubログアウト)
docker logout
docker@LesPaul:~$ docker logout
Removing login credentials for https://index.docker.io/v1/
Appendix
Docker Hub
DockerにはDockerレジストリと呼ばれる多くのDockerイメージを集権的に管理するためのホスティング機能があります。
Docker HubはDocker社が管理しているDockerレジストリです。
Docker Hubは、GitHubやBitbucket等のソースコード管理ツールと連携してコードをビルドする機能やアプリケーションのイメージを管理する機能などを備えています。
Docker Hubによって、物理サーバ/仮想マシン/クラウドにDockerイメージを配布可能となります。
アカウント登録
https://hub.docker.com
フォームを入力し送信後にメールが送信されます。
メール記載の指示に従い、アクティベーションを済ませます。
サインアップ
Welcomeページへの遷移(サインアップ完了)