| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

Docker コマンド

提供: MyMemoWiki
ナビゲーションに移動 検索に移動

| Docker | WSL | Kubernetes

Docker コマンド

| Docker | 仮想化 | Kubernetes |

コマンド

コマンド 内容
docker version バージョンの確認
docker info 現在の情報
docker pull [NAME:TAG] イメージの取得 docker pull nginx:latest
docker run -i インタラクティブ実行 docker run -i -t -h ubuntu ubuntu /bin/bash
docker run -d バックグラウンド実行 docker run --name test-nginx -d nginx -p 8080:80 nginx
docker stop [コンテナID] コンテナの停止 docker stop 5fe904cacaff
docker start [コンテナID] コンテナが残っている場合、再実行できる docker start 5fe904cacaff
docker exec 実行しているコンテナのコマンドを実行 docker exec -it 5fe904cacaff bash
docker inspect オブジェクトのインスペクト(ipアドレスを調べるなど) docker inspect 5fe
docker
docker

runコマンドオプション

コマンドオプション パラメータ 内容
-p, --publish hostPort:containerPort コンテナポートをホストに公開 docker run --name test-ginx -d -p 8080:80 nginx
-v, --volume /host:/container ボリュームをバインド docker run --name bind-eginx -d -p 8080:80 -v /mnt/c/workspaces/docker/
nginx/content:/usr/share/nginx/html:ro nginx

バージョンの確認(version)

# docker version
Client version: 1.0.0
Client API version: 1.12
Go version (client): go1.2.2
Git commit (client): 63fe64c/1.0.0
Server version: 1.0.0
Server API version: 1.12
Go version (server): go1.2.2
Git commit (server): 63fe64c/1.0.0

情報の確認(info)

# docker info
Containers: 1
Images: 3
Storage Driver: devicemapper
 Pool Name: docker-253:1-203234686-pool
 Data file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata file: /var/lib/docker/devicemapper/devicemapper/metadata
 Data Space Used: 569.2 Mb
 Data Space Total: 102400.0 Mb
 Metadata Space Used: 0.9 Mb
 Metadata Space Total: 2048.0 Mb
Execution Driver: native-0.2
Kernel Version: 3.10.0-123.el7.x86_64

イメージの取得

Docker Registry

取得(pull)

# docker pull openshift/wildfly-8-centos
Pulling repository openshift/wildfly-8-centos                                                                             
f3ba582d4042: Download complete                                                                                           
f3ba582d4042: Pulling image (latest) from openshift/wildfly-8-centos                                                      
511136ea3c5a: Download complete                                                                                           
    :
7e1fd6711692: Download complete                                                                                           
6244d7d2948c: Download complete

確認(images)

# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
openshift/wildfly-8-centos   latest              f3ba582d4042        6 days ago          539.3 MB
centos                       latest              1a7dc42f78ba        8 days ago          236.4 MB

実行

インタラクティブ実行(run –t)

  • run –t でインタラクティブにシェルを実行出来る
  • 任意のコマンドをコンテナ内で実行可能
  • 停止する場合は、Ctrl+D
# docker run -i -t -h openshift/wildfly-8-centos openshift/wildfly-8-centos /bin/bash
bash-4.1#

バックグラウンド実行(run –d)

# docker run -d openshift/wildfly-8-centos /wildfly/bin/standalone.sh 
564e5343046f97da12ba09273020eabbb7a84d4b0299f13c256b43aa449d1bb7

プロセスの確認(ps)

# docker ps
CONTAINER ID        IMAGE                               COMMAND                CREATED              STATUS              PORTS                                    NAMES
564e5343046f        openshift/wildfly-8-centos:latest   /wildfly/bin/standal   About a minute ago   Up About a minute   7600/tcp, 8080/tcp, 9990/tcp, 9999/tcp   insane_euclid  

プロセス監視(top)

# docker top 564e5343046f 
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                5739                1401                0                   23:22               ?                   00:00:00            /bin/sh /wildfly/bin/standalone.sh
root                5867                5739                14                  23:22               ?                   00:00:07            java -D[Standalone] -server -XX:+UseSerialGC -Xms40m -Xmx256m -XX:MaxPermSize=102m -XX:+AggressiveOpts -Dorg.apache.tomcat.util.LOW_MEMORY=true -DOPENSHIFT_APP_UUID= -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Dorg.jboss.resolver.warning=true -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8 -Djboss.node.name=564e5343046f -Djgroups.bind_addr=0.0.0.0 -Dorg.apache.coyote.http11.Http11Protocol.COMPRESSION=on -Dorg.jboss.boot.log.file=/wildfly/standalone/log/server.log -Dlogging.configuration=file:/wildfly/standalone/configuration/logging.properties -jar /wildfly/jboss-modules.jar -mp /wildfly/provided_m

コンテナの停止(stop)

# docker stop 564e5343046f 
564e5343046f

コンテナの強制終了(kill)

# docker kill faff5b7c7492 
faff5b7c7492

コンテナの再起動(restart)

# docker restart 564e5343046f
564e5343046f

イメージの管理

イメージの削除(rmi)

# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
openshift/wildfly-8-centos   latest              f3ba582d4042        3 weeks ago         539.3 MB
<none>                       <none>              1a7dc42f78ba        3 weeks ago         236.4 MB
# docker rmi -f 1a7dc42f78ba 
Deleted: 1a7dc42f78ba213ec1ac5cd04930011334536214ad26c8000f1eec72e302c041

コンテナ状態の確認(inspect)

# docker inspect faff5b7c7492 
[{
    "Args": [],
    "Config": {
        "AttachStderr": false,
        "AttachStdin": false,
        "AttachStdout": false,
        "Cmd": [
            "/wildfly/bin/standalone.sh"
        ],
        "CpuShares": 0,
        "Cpuset": "",
        "Domainname": "",
        "Entrypoint": null,
        "Env": [
            "HOME=/",
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "STI_SCRIPTS_URL=https://raw.githubusercontent.com/openshift/wildfly-8-centos/master/.sti/bin"
        ],
        "ExposedPorts": {
            "7600/tcp": {},
            "8080/tcp": {},
            "9990/tcp": {},
            "9999/tcp": {}
        },
        "Hostname": "faff5b7c7492",
        "Image": "openshift/wildfly-8-centos",
        "Memory": 0,
        "MemorySwap": 0,
        "NetworkDisabled": false,
        "OnBuild": null,
        "OpenStdin": false,
        "PortSpecs": null,
        "StdinOnce": false,
        "Tty": false,
        "User": "",
        "Volumes": null,
        "WorkingDir": "/opt/wildfly/source"
    },
    "Created": "2014-08-03T14:37:58.975398521Z",
    "Driver": "devicemapper",
    "ExecDriver": "native-0.2",
    "HostConfig": {
        "Binds": null,
        "ContainerIDFile": "",
        "Dns": null,
        "DnsSearch": null,
        "Links": null,
        "LxcConf": [],
        "NetworkMode": "bridge",
        "PortBindings": {
            "7600/tcp": null,
            "8080/tcp": null,
            "9990/tcp": null,
            "9999/tcp": null
        },
        "Privileged": false,
        "PublishAllPorts": false,
        "VolumesFrom": null
    },
    "HostnamePath": "/var/lib/docker/containers/faff5b7c749257ff79180b5c9b90e3cadabec91a76895c086ec4e66fd84b3733/hostname",
    "HostsPath": "/var/lib/docker/containers/faff5b7c749257ff79180b5c9b90e3cadabec91a76895c086ec4e66fd84b3733/hosts",
    "Id": "faff5b7c749257ff79180b5c9b90e3cadabec91a76895c086ec4e66fd84b3733",
    "Image": "f3ba582d4042e5e506e787e102bd122617cf4d574a32ff75ec5c5606aa60c4f0",
    "MountLabel": "system_u:object_r:svirt_sandbox_file_t:s0:c219,c329",
    "Name": "/compassionate_babbage",
    "NetworkSettings": {
        "Bridge": "docker0",
        "Gateway": "172.17.42.1",
        "IPAddress": "172.17.0.3",
        "IPPrefixLen": 16,
        "PortMapping": null,
        "Ports": {
            "7600/tcp": null,
            "8080/tcp": null,
            "9990/tcp": null,
            "9999/tcp": null
        }
    },
    "Path": "/wildfly/bin/standalone.sh",
    "ProcessLabel": "system_u:system_r:svirt_lxc_net_t:s0:c219,c329",
    "ResolvConfPath": "/etc/resolv.conf",
    "State": {
        "ExitCode": 0,
        "FinishedAt": "2014-08-19T13:58:30.659032186Z",
        "Paused": false,
        "Pid": 3503,
        "Running": true,
        "StartedAt": "2014-08-19T14:00:08.994894748Z"
    },
    "Volumes": {},
    "VolumesRW": {}
}
]