labunix's blog


debian stretchにdockerを導入する。

■debian stretchにdockerを導入する。

 How to install Docker engine on Debian 9 Stretch Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 9.3 (stretch)
Release:	9.3
Codename:	stretch


$ sudo apt-get install -y apt-transport-https dirmngr

$ w3m -dump | awk '/debian/'
debian-jessie/                              12-Apr-2017 19:11  -
debian-stretch/                             12-Apr-2017 19:11  -
debian-wheezy/                              12-Apr-2017 19:11  -

$ echo deb debian-stretch main | \
    sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

$ sudo apt-key adv --keyserver hkp:// \
    --keyserver-option http-proxy= \
    --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
Executing: /tmp/apt-key-gpghome.rJ8CAEWXKO/ --keyserver hkp:// \
  --keyserver-option http-proxy= --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
gpg: 鍵F76221572C52609D: 公開鍵"Docker Release Tool (releasedocker) <>"をインポートしました
gpg:           処理数の合計: 1
gpg:             インポート: 1

$ sudo apt-get install -y docker-engine

$ docker -v
Docker version 17.05.0-ce, build 89658be

$ sudo docker version
 Version:      17.05.0-ce
 API version:  1.29
 Go version:   go1.7.5
 Git commit:   89658be
 Built:        Thu May  4 22:09:06 2017
 OS/Arch:      linux/amd64

 Version:      17.05.0-ce
 API version:  1.29 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   89658be
 Built:        Thu May  4 22:09:06 2017
 OS/Arch:      linux/amd64
 Experimental: false


 Control and configure Docker with systemd

$ awk '/proxy/' /etc/default/docker
# If you need Docker to use an HTTP proxy, it can also be specified here.
#export http_proxy=""

$ sudo sed -i 's%.*http_proxy.*%&\nexport http_proxy=""%' /etc/default/docker

$ dpkg -L docker-engine | awk '/service$/'

$ dpkg -L docker-engine | awk '/service$/{print "cp "$1" /etc/systemd/system/"}' | sudo sh

$ sudo sed -i 's%\[Service\]%&\nEnvironment="HTTP_PROXY="%' /etc/systemd/system/docker.service

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker.service 

$ sudo systemctl show --property Environment docker

$ sudo docker search httpd | awk '/NAME|^httpd/'
NAME                                DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
httpd                               The Apache HTTP Server Project                  1412      [OK]       

$ sudo docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
f49cf87b52c1: Pull complete 
02ca099fb6cd: Pull complete 
de7acb18da57: Pull complete 
770c8edb393d: Pull complete 
0e252730aeae: Pull complete 
6e6ca341873f: Pull complete 
2daffd0a6144: Pull complete 
Digest: sha256:b5f21641a9d7bbb59dc94fb6a663c43fbf3f56270ce7c7d51801ac74d2e70046
Status: Downloaded newer image for httpd:latest

$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
httpd               latest              7239615c0645        2 weeks ago         177MB

$ sudo docker run -ti httpd /bin/bash
root@6f32436cde9b:/usr/local/apache2# exit


$ sudo docker run -ti httpd /bin/bash
[Ctrl]+p [Ctrl]+q

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
ff553f5901f3        httpd               "/bin/bash"         About a minute ago   Up About a minute   80/tcp              dreamy_pike

$ sudo docker attach ff553f5901f3
root@ff553f5901f3:/usr/local/apache2# exit