LoginSignup
3
5

More than 3 years have passed since last update.

メモ、wslでdockerを動かすまで

Last updated at Posted at 2020-04-11

このメモについて

wslからdockerを起動できるようにするだけで一日潰れたので、その過程を残す。

行き当たりばったりで再現性は不明。

実際は書いてあることも色々見当違いの可能性あり。

ここが違うとか教えていただければ助かります。

結論

wslのOSインストール直後の状態からdocker公式に沿ってインストールすれば、何も問題なく導入できた。

環境

windows 10 pro
Docker for Windows

wsl上のOS
Ubuntu 18.04 LTS

環境とかの確認コマンド

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:        18.04
Codename:       bionic
$ arch
x86_64
$ uname -a
Linux DESKTOP-RPU16NT 4.19.84-microsoft-standard #1 SMP Wed Nov 13 11:44:37 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

インストール関係

とりあえず公式を参考に進める。

【Docker 公式】Ubuntu
https://docs.docker.com/engine/install/ubuntu/#installation-methods

Qiitaに記事が一杯転がってるので、そっちを見て進めたほうが分かりやすいかも。

Docker for Windowsで快適な環境を得るまでの そこそこ長い闘い

[2019年1月版]WSL + Ubuntu で Docker が動くっ!動くぞコイツッ!

エラーがいっぱい

最終的には、エラー類の解消はQiitaの記事だけでできたかもしれない。

参考

WSL上でDockerを動かす際に躓いたこと

Docker for WindowsをWSLから呼び出せるようにしていたため
まず、自分はもともとDocker for WindowsをWSLから呼び出して使っていた。どうやらその辺りの設定が悪さをしていたようだ。

Docker for WindowsのExpose daemon on tcp://localhost:2375 without TLSのチェックを外す必要があった

dockerのイメージ作成が「cgroups: cannot find cgroup mount destination: unknown.」でエラーになる

docker daemonが動いてるかって?

$ docker ps
Cannot connect to the Docker daemon at tcp://0.0.0.0:2375. Is the docker daemon running?

パスを通す必要があるらしい

$ echo "export DOCKER_HOST='tcp://0.0.0.0:2375'"

なにか言われる

$ source ~/.bashrc
nvm is not compatible with the npm config "prefix" option: currently set to "/home/(User)/.npm-global"
Run `npm config delete prefix` or `nvm use --delete-prefix v12.16.1 --silent` to unset it.

言われたとおりに実行

$ nvm use --delete-prefix v12.16.1 --silent

コマンド通った

$ source ~/.bashrc

まだ使えそうにない

$ docker version

Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b7f0
 Built:             Wed Mar 11 01:25:46 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Cannot connect to the Docker daemon at tcp://0.0.0.0:2375. Is the docker daemon running?

cgroupsについて調べる

$ sudo docker run hello-world

docker: Error response from daemon: cgroups: cannot find cgroup mount destination: unknown.
ERRO[0001] error waiting for container: context canceled

cgroups: cannot find cgroup mount destination: unknown

コマンドでディレクトリ作成とマウントを行う

$ sudo mkdir /sys/fs/cgroup/systemd
$ sudo mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd

グループ登録

$ sudo usermod -aG docker $(whoami)

Dockerサービスの起動と自動起動の設定

参考
Docker公式 systemd で Docker の管理・設定

Docker公式 Docker の設定と実行

Q. エラーが出る: "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"

RedHat系のコマンドだったため違うっぽい

$ sudo systemctl enable docker
Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable docker

dockerデーモンステータス確認

$ sudo service docker status
 * Docker is not running

コマンド打ち間違い?

$ service start docker
start: unrecognized service
System has not been booted with systemd as init system (PID 1). Can't operate.

Docker for WindowsのExpose daemon on tcp://localhost:2375 without TLSのチェックを外したり、入れたりガチャガチャ。

dockerデーモン起動

$ sudo service docker start
 * Starting Docker: docker

もう一回確認

$ sudo service docker status
 * Docker is running

使用できるか確認

$ sudo 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-composeのインストールしなくちゃ

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