Windows10(WSL)にDocker環境を構築

目的

WindowsでWSLを利用して、Dockerを用いたpython開発環境を構築

参考サイト

  • https://qiita.com/guchio/items/3eb0818df44fdbab3d14
  • https://qiita.com/unhurried/items/43e9afda62c51f0975f5

まとめ

  • はじめ最新のUbuntu 18.04で試したが「MS_SLAVE 」問題でハマる

作業

以下の作業は、ubuntuのターミナルを管理者権限で立ち上げて実行します。
もともと、WSLとしてUbuntu 18.04を構築済みだったので、それを流用しました。
(それが、あとでハマることになるとは。。。)

 

Dockerのインストール

sudo apt update
sudo apt upgrade
sudo apt install docker.io
sudo cgroupfs-mount
sudo usermod -aG docker $USER
sudo service docker start

インストールできたか確認

$ docker --version
Docker version 18.06.1-ce, build e68fc7a

イメージを共有可能な格納先であるレジストリから、特定のDockerイメージを入手

 

sudo docker pull python:3.7

エラーがでた

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Docker deamonが動いているか確認

$ sudo service docker status
* Docker is not running

動いていない。ネットを調べると、ubuntuの再起動が必要と書いていたので

一度、ターミナルを閉じて、再度実行する。

$ sudo service docker start
* Starting Docker: docker [ OK ]
$ sudo service docker status
* Docker is running

インストールを実行

$ sudo docker pull python:3.7
3.7: Pulling from library/python
54f7e8ac135a: Extracting [==================================================>] 45.32MB/45.32MB
d6341e30912f: Download complete
087a57faf949: Download complete
5d71636fb824: Download complete
0c1db9598990: Download complete
bfb904e99f24: Download complete
78a3d3a96a32: Download complete
885a0ed92c89: Download complete
dd7cc9ace242: Download complete
failed to register layer: Error processing tar file(exit status 1): invalid argument

どうも、最新のDockerではエラーになるよう

https://qiita.com/guchio/items/3eb0818df44fdbab3d14

今一度、ググって対応を調査。以下のサイトに対応策が記載していたのでそこに倣って実行。

ubuntuのバージョンを18.04から16.04に変更してリトライ

sudo apt-get remove -y docker docker-engine docker.io


$ sudo apt-get remove -y docker docker-engine docker.io
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'docker-engine' is not installed, so not removed
Package 'docker' is not installed, so not removed
The following packages were automatically installed and are no longer required:
bridge-utils cgroupfs-mount pigz ubuntu-fan
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
docker.io
0 upgraded, 0 newly installed, 1 to remove and 5 not upgraded.
After this operation, 197 MB disk space will be freed.
(Reading database ... 100998 files and directories currently installed.)
Removing docker.io (18.06.1-0ubuntu1~18.04.1) ...
'/usr/share/docker.io/contrib/nuke-graph-directory.sh' -> '/var/lib/docker/nuke-graph-directory.sh'
invoke-rc.d: could not determine current runlevel
* Stopping Docker: docker [ OK ]
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

 

sudo apt-get update


$ sudo apt-get update
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
Hit:2 http://archive.ubuntu.com/ubuntu bionic InRelease
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [444 kB]
Get:6 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [581 kB]
Get:7 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [3260 B]
Get:8 http://archive.ubuntu.com/ubuntu bionic-backports/universe Translation-en [1480 B]
Fetched 1276 kB in 18s (70.6 kB/s)

 

sudo apt install libltdl7 -y


$ sudo apt install libltdl7 -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
libltdl7 is already the newest version (2.4.6-2).
libltdl7 set to manually installed.
The following packages were automatically installed and are no longer required:
  bridge-utils cgroupfs-mount pigz ubuntu-fan
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.

 

curl -O https://download.docker.com/linux/debian/dists/stretch/pool/stable/amd64/docker-ce_17.09.0~ce-0~debian_amd64.deb


$ curl -O https://download.docker.com/linux/debian/dists/stretch/pool/stable/amd64/docker-ce_17.09.0~ce-0~debian_amd64.deb
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 20.2M  100 20.2M    0     0  3051k      0  0:00:06  0:00:06 --:--:-- 3151k

sudo dpkg -i docker-ce_17.09.0\~ce-0\~debian_amd64.deb

$ sudo dpkg -i docker-ce_17.09.0\~ce-0\~debian_amd64.deb
(Reading database ... 100800 files and directories currently installed.)
Preparing to unpack docker-ce_17.09.0~ce-0~debian_amd64.deb ...
Unpacking docker-ce (17.09.0~ce-0~debian) ...
Setting up docker-ce (17.09.0~ce-0~debian) ...
Installing new version of config file /etc/init.d/docker ...
Installing new version of config file /etc/init/docker.conf ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
invoke-rc.d: could not determine current runlevel
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for systemd (237-3ubuntu10.9) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

 

sudo usermod -aG docker $USER


$ sudo usermod -aG docker $USER

 

ubuntuのターミナルを閉じて、再度立ち上げなおす。


$ sudo service docker status
* Docker is running

 


$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

 

hello-dockerが成功したので、pythonの開発環境を準備する。


$ docker pull python:3.6
3.6: Pulling from library/python
54f7e8ac135a: Pull complete
d6341e30912f: Pull complete
087a57faf949: Pull complete
5d71636fb824: Pull complete
0c1db9598990: Pull complete
2eeb5ce9b924: Pull complete
a8c530378055: Pull complete
687ed2fb2a0d: Pull complete
620aea26e853: Pull complete
Digest: sha256:fc34d5b6cf5d00a6139a74370dc27ddc9ce18303e2210d0f199a6050cc29aa45
Status: Downloaded newer image for python:3.6

 

プルに成功したので、docker環境を作成


$ docker run --name python36 -i -t python:3.6 /bin/bash
root@552553ee33e1:/# python --version
Python 3.6.7
root@552553ee33e1:/#

 

結果

About: ken


コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください