LoginSignup
9
15

More than 5 years have passed since last update.

WSLでDockerを動かす

Last updated at Posted at 2019-02-15

WSLでDockerを動かす

Windows10には、WSL(Windows Subsystem for Linux)と呼ばれる、Linux環境を動作することが出来る機能が備わっています。この環境でDockerを動かすことを確認します。

すみません、私の環境では、以下の手順だとコンテナからインターネットへ通信することが出来ません。要調査。ネットワーク疎通をしないものであれば動作可能です

とりあえず普通にやってみる

とりあえず普通に、WSL(Ubuntu18.04) で Docker(18.06.2) を動かしてみたら、エラーでうごきませんでした。docker pull の時に、以下のエラーが発生します。

root@tora-PC:~# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a02a4930cb5d: Extracting [==================================================>]  75.17MB/75.17MB
failed to register layer: Error processing tar file(exit status 1): invalid argument

Docker Install

現時点では、Dockerバージョン17.09.1 以降のものは、WSLでは動作しないようで、17.09.0 を Installすると正常に動作します

Repositoryの設定

sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   bionic \
   stable"
sudo apt update

docker-ce(17.09.0)のdebファイルをダウンロードします

wget https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-ce_17.09.0~ce-0~ubuntu_amd64.deb

DockerをInstallします

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

Userの設定。ログインユーザをdocker group に所属することにより、dockerコマンドを sudo 無しで実行を出来るようにする

sudo cgroupfs-mount
sudo usermod -aG docker $USER

Dockerを開始します。systemctl は WSLでは動作しないため、serviceコマンドで開始します。
WSL や ターミナルソフトを管理者権限で動作させると正常にDockerを開始できます

sudo service docker start

正常に開始されたことを確認します

> sudo service docker status
* Docker is running

Dockerの動作確認のために、hello-world コンテナを稼働します

docker run hello-world

実行例

> docker run hello-world

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/

参考URL

どうしても Docker on Ubuntu 18.04 on WSL したかった
https://qiita.com/guchio/items/3eb0818df44fdbab3d14

9
15
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
9
15