Index ソフト・ハード Dockerタスク | Dockerタスク |
機能・要件 構成・方式 タスク コマンド コンテナ生成 コンテナ開始 ポート確認 イメージ検索 イメージ一覧 イメージ入手 イメージ保存 イメージ作成 DockerFile Compose httpd centos hello-world サービス状態 導入 ToolBox導入 |
コマンド
DockerFile ・DockerFile、DockerFileの仕様、DockerFile内の命令などの形式 ・記述例 httpdDockerCompose ・DockerToolbox で DockerMachine を インストールした場合、 同時に DockerCompose もインストールされる。 $ docker-compose --version docker-compose version 1.24.1, build xxxxhttpd ・ApacheのWebサーバイメージhttpdを、コンテナとして起動 $ docker run --name web1 -d -p 8080:80 httpd バックグラウンドで実行 ホストマシンの8080番ポートをコンテナの80番ポートにマッピング ローカルホストにイメージが無く、DockerHubからイメージをダウンロード ブラウザでホストマシンにポート番号8080を指定してアクセスcentos (The official build of CentOS.) ・対話型インタフェースを持つプログラムをフォアグラウンドで起動 ※rootユーザーがコンソールでログイン中は、プログラムを動かせる。 $ docker search centos $ docker pull centos $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest feb5d9fea6a5 2 months ago 13.3kB centos latest 5d0da3dc9764 3 months ago 231MB・CentOS7のサーバイメージcentosを、コンテナとして起動 $ docker run -it --name CentOS centos:latest /bin/bash ※/bin/bash :コンテナで実行するコマンド 疑似端末を有効にし、標準入力をオープンしたままにする。 コンテナ名は、CentOS7 起動すると、コンソールに接続され、シェルのプロンプト 「Ctrl+p」+「Ctrl+q」で、コンテナを終了させずに、ホストのプロンプトに戻る。 もう一度接続するには、docker attachコマンドを使用($ docker attach CentOS7) 「Ctrl+d」でコンテナが終了 @1aeafbef2493 /]# (bashの新しいプロンプト) @1aeafbef2493 /]# uname -r 3.10.0-1160.49.1.el7.x86_64 @1aeafbef2493 /]# ps -ax (コンテナー実行環境などのプロセスは隠ぺい) PID TTY STAT TIME COMMAND 1 pts/0 Ss 0:00 /bin/bash (プロセスID:1 で動いている。) 16 pts/0 R+ 0:00 ps -ax @1aeafbef2493 /]# exit # (コンテナの実行は終了) # docker run -it centos:latest /bin/bash (同じコマンドで、新しいコンテナを作成) @10f46d6be7d4 /]# # docker ps -a (別の端末から確認、停止中のコンテナーも表示)
CONTAINER ID IMAGE COMMAND CREATED STATUS ・・・
10f46d6be7d4 centos:latest "/bin/bash" 12 minutes ago Up 12 minutes
1aeafbef2493 centos:latest "/bin/bash" 59 minutes ago Exited (0) 51 minutes ago
425059dff821 hello-world "/hello" 4 hours ago Exited (0) 4 hours ago
hello-world ・公式のhello-worldコンテナのイメージを取得し、コンテナを実行 # docker run hello-world・イメージにはCで書かれた説明用文字を表示するバイナリが入っている。 表示の上の5行は、初めてイメージを取得する場合に表示されるメッセージ・ローカルに hello-world:latest が存在しないため DockerHub からイメージを取得 $ docker images イメージ情報 REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest feb5d9fea6a5 2 months ago 13.3kB・イメージの詳細情報 $ docker inspect hello-world:latestイメージを検索 $ docker search centos
サービスの状態を確認 $ docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.7.1-docker)
scan: Docker Scan (Docker Inc., v0.12.0)
Server:
Containers: 2
Running: 0
Paused: 0
Stopped: 2
Images: 1
Server Version: 20.10.12
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc version: v1.0.2-0-g52b36a2
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1160.49.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.607GiB
Name: kvmxx.localdomain
ID: NPRN:UCAC:5TW7:3K4E:X7QT:BF3E:ZIMS:FK36:TXJV:DDBM:6YN5:6HMH
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
|
All Rights Reserved. Copyright (C) ITCL |