Docker

Docker on WSL2

since 2020-08-22

WSL2 を Windows 10 version 1909 で有効化した。

Docker Desktop

Docker Desktop 2.3.0.4 をインストールしようとしたが、

Docker Desktop requires Windows 10 Pro/Enterprise (15063+) or Windows 10 Home (19018+).

とのことだった。残念。

apt

Ubuntu-18.04 だと思って素直に入れようとしてみる

前半は省略するが、できた。

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

$ docker --version
Docker version 19.03.12, build 48a66213fe

$ sudo service docker start
 * Starting Docker: docker

certbot を動かす例

$ sudo docker run -it --rm --entrypoint /bin/sh certbot/certbot
Unable to find image 'certbot/certbot:latest' locally
latest: Pulling from certbot/certbot

Status: Downloaded newer image for certbot/certbot:latest
/opt/certbot # certbot --help

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  certbot [SUBCOMMAND] [options] [-d DOMAIN] [-d DOMAIN] ...

中略

More detailed help:

  -h, --help [TOPIC]    print this message, or detailed help on a topic;
                        the available TOPICS are:

   all, automation, commands, paths, security, testing, or any of the
   subcommands or plugins (certonly, renew, install, register, nginx,
   apache, standalone, webroot, etc.)
  -h all                print a detailed help page including all topics
  --version             print the version number
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/opt/certbot # certbot --version
certbot 1.7.0
/opt/certbot # exit

$
$ sudo docker run -it --rm certbot/certbot --version
certbot 1.7.0

Docker on WSL1

since 2018-07-10

setup

  • Windows 10 version 1803 (x64) Home
  • WSL Ubuntu 16.04

https://www.reddit.com/r/bashonubuntuonwindows/comments/8cvr27/docker_is_running_natively_on_wsl/

http://www.nuits.jp/entry/docker-on-wsl

書かれているとおりで環境構築、動作を確認

.bashrc の最後に cgroupfs-mount を追加

sudo systemctl enable docker を実行してサービスを自動起動

試せたこと

$ sudo docker run --rm hello-world

$ sudo docker run -it ubuntu bash

$ sudo docker run -it --rm -p 8080:80 nginx:latest

Python イメージという話

https://qiita.com/RyoMa_0923/items/7c0b22dd3f284472e18d

$ sudo docker pull python:3.6
$ sudo docker run -d --name hoge python:3.6 /bin/bash -c 'tail -f /dev/null'
$ sudo docker exec -it hoge /bin/bash
rpc error: code = 13 desc = invalid header field value "oci runtime error: exec failed: container_linux.go:247: starting container process caused \"could not create session key: function not implemented\"\n"

動いているようだが?

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
f207175bc4bb        python:3.6          "/bin/bash -c 'tai..."   2 minutes ago       Up About a minute                       hoge

もっと単純なことからやり直すか

$ sudo docker run -d --name hoge2 ubuntu /bin/bash -c 'tail -f /dev/null'

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
64a1e42b1617        ubuntu              "/bin/bash -c 'tai..."   13 seconds ago      Up 5 seconds                            hoge2
f207175bc4bb        python:3.6          "/bin/bash -c 'tai..."   5 minutes ago       Up 5 minutes                            hoge

$ sudo docker exec -it hoge2 /bin/bash
rpc error: code = 13 desc = invalid header field value "oci runtime error: exec failed: container_linux.go:247: starting container process caused \"could not create session key: function not implemented\"\n"

そもそも docker run -d した環境に接続できない?

docker kill はできる

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
64a1e42b1617        ubuntu              "/bin/bash -c 'tai..."   13 minutes ago      Up 13 minutes                           hoge2
f207175bc4bb        python:3.6          "/bin/bash -c 'tai..."   19 minutes ago      Up 19 minutes                           hoge

$ sudo docker kill hoge
hoge

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
64a1e42b1617        ubuntu              "/bin/bash -c 'tai..."   13 minutes ago      Up 13 minutes                           hoge2

$ sudo docker kill hoge2
hoge2

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Windows 再起動後

2018-07-11

再起動したらもういちど下記が必要らしい

(1) Ubuntu (16.04) を管理者で実行

sudo service docker start

(2) いったん閉じて、もう一度 Ubuntu (16.04) を管理者で実行

sudo cgroupfs-mount && sudo service docker start

確認

sudo docker run –rm hello-world

docker.txt · 最終更新: 2020/09/05 14:24 by Takuya Nishimoto
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0