LoginSignup
19
20

More than 3 years have passed since last update.

WSL(Ubuntu 18.04)上にDockerをインストールしてdocker run hello-worldまで

Last updated at Posted at 2019-08-12

想定している読者

・Windows 10 pro (version 1809)
・WSL(Ubuntu18.04)

これらを使ってDockerを使用したい方。しかし何故か、
docker run hello-worldを実行すると次のようなエラーが出る方。

docker: Error response from daemon: failed to start shim: exec: "docker-containerd-shim": executable file not found in $PATH: unknown.
ERRO[0005] error waiting for container: context canceled

解決策・結論

上記のエラーは、WSLでdocker version 18.09.7を使用しているからです。
恐らく、WSLでdocker version 18.09.7はまだサポートされていないと考えられます。
現時点(2019/08/12)で、WSL上にインストールすべきdockerのバージョンは17.12.1です。※CE(コミュニティエディション)において。

ここからは、
1. version 17.12.1のインストールの仕方
2. sudo apt -y upgradeしてもdockerのversionを変更させない方法
の二点を説明していきます。

1.version17.12.1のインストール&起動

$ sudo apt install docker.io=17.12.1-0ubuntu1
$ sudo cgroupfs-mount
$ sudo usermod -aG docker $USER
$ sudo service docker start

毎回、sudo cgroupfs-mount && sudo service docker startするのは面倒なので、Docker.shファイルを作成します。(ファイル名はなんでも良い)

Docker.sh
#!/bin/sh
 pass=''  #Ubuntuのパスワード
 echo "$pass" | sudo -S cgroupfs-mount && sudo service docker start
 sleep 15
 docker version

ファイルに権限を与えます。

$ chmod 700 Docker.sh

このファイルのあるディレクトリで、./Docker.shとコマンドを入力します。
※sudoの-Sオプションは「パスワードを端末ではなく標準入力から読み込む」という意味です。sudo service docker startの後に、標準入力でパスワードを求められます。
#!/bin/shに関しては、こちらの記事が詳しいです。

2.特定のパッケージをupgradeさせない方法

apt-markを使い、パッケージのversionを固定する。

$ sudo apt-mark hold docker.io
 docker.io set on hold.

holdしたパッケージの一覧表示

$ apt-mark showhold
  docker.io

以上のように設定することで、sudo apt -y upgradeしてもversionが勝手に変更されないです。

3.docker run hello-world

WSL(Ubuntu18.04)を一度閉じて、管理者権限で開いてください。
先ほど、作成したDocker.shでdockerを起動します。

$ ./Docker.sh
* Starting Docker: docker      [ ok ]                                                                                                                             
Client:
 Version:       17.12.1-ce
 API version:   1.35
 Go version:    go1.10.1
 Git commit:    7390fc6
 Built: Wed Apr 18 01:23:11 2018
 OS/Arch:       linux/amd64

Server:
 Engine:
  Version:      17.12.1-ce
  API version:  1.35 (minimum version 1.12)
  Go version:   go1.10.1
  Git commit:   7390fc6
  Built:        Wed Feb 28 17:46:05 2018
  OS/Arch:      linux/amd64
  Experimental: false
$ 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/

これで完了です:v:

参考記事

Windows10のバージョン1809のWSLでDockerが動作する環境を構築した

19
20
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
19
20