Dockerをubuntuで使うためには?

手順が古いところがあるのでupdateしつつ以下の手順で実施

sudo apt update
sudo apt remove docker docker-engine docker.io
sudo apt install -y \
    linux-image-extra-$(uname -r) \
    linux-image-extra-virtual
sudo apt install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
sudo apt update
sudo apt install docker-ce

Docker run

root@ubuntu1604-sand:~# docker run -it ubuntu
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
ae79f2514705: Pull complete
5ad56d5fc149: Pull complete
170e558760e8: Pull complete
395460e233f5: Pull complete
6f01dc62e444: Pull complete
Digest: sha256:506e2d5852de1d7c90d538c5332bd3cc33b9cbd26f6ca653875899c505c82687
Status: Downloaded newer image for ubuntu:latest
root@da99b4c6f769:/#
root@da99b4c6f769:/#

Misc checker

Network

  • interface
    root@ubuntu1604-sand:~# ip a
    ///////
    3: docker0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state UP group default
      link/ether 02:42:b7:f3:14:1b brd ff:ff:ff:ff:ff:ff
      inet 172.17.0.1/16 scope global docker0
         valid_lft forever preferred_lft forever
      inet6 fe80::42:b7ff:fef3:141b/64 scope link
         valid_lft forever preferred_lft forever
    ///////
    
  • docker network
    root@ubuntu1604-sand:~# docker network ls
    NETWORK ID          NAME                DRIVER              SCOPE
    db4c63b9a818        bridge              bridge              local
    d481d6a6b105        host                host                local
    d89ef5fa06f3        none                null                local
    
  • docker network inspect
    root@ubuntu1604-sand:~# docker network inspect bridge
    [
      {
          "Name": "bridge",
          "Id": "db4c63b9a818a99458c52f7818635cc00fd77b15b03b0e4b70a4e37760bbc94f",
          "Created": "2017-10-18T07:27:23.090097897Z",
          "Scope": "local",
          "Driver": "bridge",
          "EnableIPv6": false,
          "IPAM": {
              "Driver": "default",
              "Options": null,
              "Config": [
                  {
                      "Subnet": "172.17.0.0/16"
                  }
              ]
          },
          "Internal": false,
          "Attachable": false,
          "Ingress": false,
          "ConfigFrom": {
              "Network": ""
          },
          "ConfigOnly": false,
          "Containers": {},
          "Options": {
              "com.docker.network.bridge.default_bridge": "true",
              "com.docker.network.bridge.enable_icc": "true",
              "com.docker.network.bridge.enable_ip_masquerade": "true",
              "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
              "com.docker.network.bridge.name": "docker0",
              "com.docker.network.driver.mtu": "1500"
          },
          "Labels": {}
      }
    ]
    
  • docker run -itd ubuntu
  • docker attach
  • Ctrl+p + Ctrl+q
  • containerのお掃除
    docker ps |awk '{print $1}' | grep -v CONTAINER | xargs -l docker rm -f
    
  • burst 起動
    root@ubuntu1604-sand:~# for i in [1 2 3 4 5]; do docker run -itd ubuntu; done
    ba55666235c6d8fe6e081258904e4cae738e87a7e3ff9761fb28feccdc9497e0
    7309238f8559e226ec7fdaa917cb2b3afeca6287b9305d99c34eef21a08992c5
    235d2d4f5dbb3cfb279ca314bc05f0825eebe6b8b29e0240a405e2bc122ca724
    ab00ec1bc49ddcbdecf794056670d2bcff98109bca8561a5769da1804e9e926b
    0355c1eeebe3b3e469174fdf8b149672fae9c5f9ebefbf0042bb0a7ceaa3c066
    

To help the humans, Docker also supplies containers with a randomly-generated name from two words, joined by an underscore, e.g. evil_ptolemy. This can make it easier to tell one container from another, but the random names don’t give any more insight into the container function than the UUID.
- https://www.digitalocean.com/community/tutorials/naming-docker-containers-3-tips-for-beginners -

root@ubuntu1604-sand:~# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
6ed929c157b3        ubuntu              "/bin/bash"         About an hour ago   Up About an hour                        thirsty_joliot
6a23db61e574        ubuntu              "/bin/bash"         About an hour ago   Up About an hour                        priceless_saha
930a48641895        ubuntu              "/bin/bash"         About an hour ago   Up About an hour                        flamboyant_hodgkin
a357bec9ce4e        ubuntu              "/bin/bash"         About an hour ago   Up About an hour                        fervent_yalow
  • tmux
  • ip reachiablity check
    apt update
    apt install -y iputils-ping net-tools 
    
  • netstat -untap
  • ping-pong
    #ping <some container's ip address>
    

image

Reference

  • Procedure for docker official
    https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/