LoginSignup
2
3

More than 5 years have passed since last update.

Windows10Home(WSL)でDocker勉強用環境の構築メモ

Last updated at Posted at 2018-11-08

やりたいこと

dockerを勉強したいが、サーバ環境を持っていない。
家に唯一あるWindows10HomeのPCでなんとか頑張りたい。

ゴール

  • dockerコマンドが使えるようになる
  • docker-composeが使えるようになる

WSL上ではdockerは動くけどdocker-composeが使えないらしい(2018/11/08時点)
Running docker compose on windows ubuntu subsystem

環境

  • Windows 10 Home
  • Ubuntu 16.04

Ubuntuのバージョンは16.04を入れる。
最新版や18.04だとうまく動かなかった。

前提

Windows Subsystem for Linux(WSL)を構築し、Ubuntuがインストールされている。

dockerの導入

Ubuntuを管理者で起動する。
以下のコマンドを入力する。

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

Ubuntuを管理者で再起動する。
以下のコマンドを入力する。

$ sudo cgroupfs-mount
$ sudo service docker start

dockerの確認

インストールされたバージョンを確認する。

$ docker version
Client:
 Version:      17.03.2-ce
 API version:  1.27
 Go version:   go1.6.2
 Git commit:   f5ec1e2
 Built:        Thu Jul  5 23:07:48 2018
 OS/Arch:      linux/amd64

Server:
 Version:      17.03.2-ce
 API version:  1.27 (minimum version 1.12)
 Go version:   go1.6.2
 Git commit:   f5ec1e2
 Built:        Thu Jul  5 23:07:48 2018
 OS/Arch:      linux/amd64
 Experimental: false

helloworldしてみる。

$ 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/

docker-composeの導入

以下のコマンドを入力する。
Compose file version 3.0が使いたかったため、1.13.0 以降を入れる。
Compose and Docker compatibility matrix

$ sudo -i
# curl -L "https://github.com/docker/compose/releases/download/1.13.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# sudo apt install docker-compose

docker-composeの確認

Jenkinsを立ち上げてみる。

docker-compose.yml
version: "3"
services:
  master:
    container_name: master
    image: jenkinsci/jenkins:2.142-slim
    ports:
      - 8080:8080
    volumes:
      - ./jenkins_home:/var/jenkins_home

実行結果は以下の通りエラー。

$ docker-compose up
Creating network "jenkins_default" with the default driver
ERROR: Failed to Setup IP tables: Unable to enable NAT rule:  (iptables failed: iptables --wait -t nat -I POSTROUTING -s 172.18.0.0/16 ! -o br-d17acf2c8392 -j MASQUERADE: iptables: Invalid argument. Run `dmesg' for more information.

参考

2
3
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
2
3