LoginSignup
8
8

More than 5 years have passed since last update.

Docker Memo

Last updated at Posted at 2015-06-06

Docker Overview

  • Docker:https://www.docker.com/
  • Docker社が開発するOSSのコンテナ型仮想化ソフトウェア
  • ハイパーバイザー型の仮想化と比較して、少ないリソースで効率よくアプリケーションを実行できる
  • Docker = Docker Engine + Docker Hub

Docker Command Sample

Show docker information

core@localhost ~ $ docker info
Containers: 1
Images: 5
Storage Driver: overlay
 Backing Filesystem: extfs
Execution Driver: native-0.2
Kernel Version: 4.0.3
Operating System: CoreOS 681.0.0
CPUs: 1
Total Memory: 493.9 MiB
Name: localhost
ID: R6ZV:YW52:C6GE:GUD3:QSTR:LXFV:LBCH:ZGSK:YQN6:EWDV:UORV:UCCJ

Download docker images and Show downloaded images

  • Download docker images
    • docker pull [イメージ名]:[タグ名]
      • [イメージ名]:Docker Hub から好みのイメージを選択
      • [タグ名]:特に指定がなければ、latestを指定
core@localhost ~ $ docker pull ubuntu:latest
latest: Pulling from ubuntu
e118faab2e16: Pull complete 
7e2c5c55ef2c: Pull complete 
e04c66a223c4: Pull complete 
fa81ed084842: Already exists 
ubuntu:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:738edd684282277c07f23277718e43562daf2ee210f7aca9a13fae65f0159ddd
Status: Downloaded newer image for ubuntu:latest
  • Show docker images
core@localhost ~ $ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              latest              fa81ed084842        5 days ago          188.3 MB
alpine              latest              8697b6cc1f48        8 days ago          5.238 MB

Create docker container from docker images

  • Create docker container from images
core@localhost ~ $ docker run -it --name uTest ubuntu /bin/bash
root@8828b2759963:/# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.2 LTS"
root@8828b2759963:/# 
  • Show docker all containers
    • docker ps [-a]: [-a] Optionをつけると停止中のコンテナも表示
core@localhost ~ $ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
8828b2759963        ubuntu:latest       "/bin/bash"         9 minutes ago       Exited (127) 5 seconds ago                       uTest               

Create docker images from docker container

  • Install nginx in docker container
core@localhost ~ $ docker start -a uTest
root@8828b2759963:/# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.2 LTS"
root@8828b2759963:/# apt-get install nginx
Reading package lists... Done
Building dependency tree       
Reading state information... Done
....
Setting up nginx-common (1.4.6-1ubuntu3) ...
Processing triggers for ureadahead (0.100.0-16) ...
Setting up nginx-core (1.4.6-1ubuntu3) ...
invoke-rc.d: policy-rc.d denied execution of start.
Setting up nginx (1.4.6-1ubuntu3) ...
Processing triggers for libc-bin (2.19-0ubuntu6.6) ...
Processing triggers for sgml-base (1.26+nmu4ubuntu1) ...
  • Create docker images from its container
    • docker commit [コンテナー名]|[コンテナーID] [[ユーザー名]/][イメージ名]
core@localhost ~ $ docker ps -a         
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES
8828b2759963        ubuntu:latest       "/bin/bash"         23 minutes ago      Exited (127) 41 seconds ago                       uTest               
core@localhost ~ $ docker commit uTest daicho/ubuntu-nginx 
63a2eb92b14d7ad8183aaed48360635b04d1f0b51d6644790ba706a9a6138229
core@localhost ~ $ docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
daicho/ubuntu-nginx   latest              63a2eb92b14d        8 seconds ago       206.4 MB
ubuntu                latest              fa81ed084842        5 days ago          188.3 MB
alpine                latest              8697b6cc1f48        8 days ago          5.238 MB

Run docker container on Background

  • Run nginx in docker container on Background
core@localhost ~ $ docker run -d -p 80:80 --name nginx1 daicho/ubuntu-nginx /usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf
63998668d76a25e644f5589265971fb484fe7ce65a2f2e0d8a3040985be72870
  • Check status of docker container and nginx
core@localhost ~ $ docker run -d -p 80:80 --name nginx1 daicho/ubuntu-nginx /usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf
63998668d76a25e644f5589265971fb484fe7ce65a2f2e0d8a3040985be72870
core@localhost ~ $ docker ps
CONTAINER ID        IMAGE                        COMMAND                CREATED             STATUS              PORTS                NAMES
63998668d76a        daicho/ubuntu-nginx:latest   "/usr/sbin/nginx -g    2 minutes ago       Up 2 minutes        0.0.0.0:80->80/tcp   nginx1
core@localhost ~ $ curl localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
  • Stop docker container
core@localhost ~ $ docker ps
CONTAINER ID        IMAGE                        COMMAND                CREATED             STATUS              PORTS                NAMES
63998668d76a        daicho/ubuntu-nginx:latest   "/usr/sbin/nginx -g    3 minutes ago       Up 3 minutes        0.0.0.0:80->80/tcp   nginx1              
core@localhost ~ $ docker stop nginx1
nginx1
core@localhost ~ $ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Remove docker container and downloaded images

  • Remove docker container
core@localhost ~ $ docker ps -a
CONTAINER ID        IMAGE                        COMMAND                CREATED             STATUS                          PORTS               NAMES
63998668d76a        daicho/ubuntu-nginx:latest   "/usr/sbin/nginx -g    5 minutes ago       Exited (0) About a minute ago                       nginx1             
core@localhost ~ $ docker rm nginx1
nginx1
core@localhost ~ $ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES
  • Remove docker images
core@localhost ~ $ docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
daicho/ubuntu-nginx   latest              63a2eb92b14d        15 minutes ago      206.4 MB
ubuntu                latest              fa81ed084842        5 days ago          188.3 MB
alpine                latest              8697b6cc1f48        8 days ago          5.238 MB
core@localhost ~ $ docker rmi daicho/ubuntu-nginx
Untagged: daicho/ubuntu-nginx:latest
Deleted: 63a2eb92b14d7ad8183aaed48360635b04d1f0b51d6644790ba706a9a6138229
core@localhost ~ $ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              latest              fa81ed084842        5 days ago          188.3 MB
alpine              latest              8697b6cc1f48        8 days ago          5.238 MB
core@localhost ~ $ 

Reference Page

8
8
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
8
8