LoginSignup
9
5

More than 3 years have passed since last update.

Docker For Desktop のセットアップとエラー対応事例

Last updated at Posted at 2019-05-28

概要

  • Linux以外でDockerを使ったことがなかったのでWindows版の導入メモ
  • 少し前まではDockerForWindowsという名称だった
  • 所感として結構インストールつまづく印象
  • インストールするとWindowsがすっごい重くなるので注意
  • 使用できるようになるまでエラーいくつかエラーに遭遇したので対応メモも記載
  • WindowsDockerはLinuxに比べて不安定な気がしてならない。エラーが多い。

サインイン

ダウンロード

インストール

セットアップ

  • ステップに従って設定
  • 画面の案内通りgit cloneでリソースをダウンロードしてくる

$ ls -l
total 8
drwxr-xr-x 1 ezaki 1049089 0 5月  24 17:44 birthday2019/
drwxr-xr-x 1 ezaki 1049089 0 5月  24 17:44 cheers2019/
  • 画面の案内通りビルドをする
  • ここで結構つまづく

遭遇したエラー

エラー:1

$ docker build -t hoge/cheers2019 .
unable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx C:\repo\doodle\Dockerfile: The system cannot find the file specif                                     ied.

エラー:2

$ docker build -t hoge/cheers2019 .
error during connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.39/buildbuildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&
cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=nvkpxkntbjfq7qlbs19i0jtm5&shmsize=0&t=hoge%2Fcheers2019&target=&ulimits=null&version=1: open //./pipe/docker_engine:The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.
  • 以下の記事などを参考

 ビルド出力

  • ビルドが成功すると以下のような出力
$ cd /c/repo/doodle/cheers2019/;docker build -t hoge/cheers2019 .
Sending build context to Docker daemon  13.31kB
Step 1/9 : FROM golang:1.11-alpine AS builder
1.11-alpine: Pulling from library/golang
e7c96db7181b: Pulling fs layer
5297bd381816: Pulling fs layer
3a664477889c: Pulling fs layer
f235158035b8: Pulling fs layer
0ebee1528520: Pulling fs layer
f235158035b8: Waiting
0ebee1528520: Waiting
3a664477889c: Verifying Checksum
3a664477889c: Download complete
5297bd381816: Verifying Checksum
5297bd381816: Download complete
e7c96db7181b: Verifying Checksum
e7c96db7181b: Download complete
0ebee1528520: Verifying Checksum
0ebee1528520: Download complete
e7c96db7181b: Pull complete
5297bd381816: Pull complete
3a664477889c: Pull complete
f235158035b8: Verifying Checksum
f235158035b8: Download complete
f235158035b8: Pull complete
0ebee1528520: Pull complete
Digest: sha256:ef839362daebf5e5b03113d48a7f02f42f5090ccf4eb5f2e915db3fc1307bdbd
Status: Downloaded newer image for golang:1.11-alpine
 ---> 419986b2b50a
Step 2/9 : RUN apk add --no-cache git
 ---> Running in 34d76c6cd0b6
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/6) Installing nghttp2-libs (1.35.1-r0)
(2/6) Installing libssh2 (1.8.2-r0)
(3/6) Installing libcurl (7.64.0-r1)
(4/6) Installing expat (2.2.6-r0)
(5/6) Installing pcre2 (10.32-r1)
(6/6) Installing git (2.20.1-r0)
Executing busybox-1.29.3-r10.trigger
OK: 20 MiB in 21 packages
Removing intermediate container 34d76c6cd0b6
 ---> 9cb059355c9a
Step 3/9 : RUN go get github.com/pdevine/go-asciisprite
 ---> Running in e62fbe601402
Removing intermediate container e62fbe601402
 ---> d3cc7008df60
Step 4/9 : WORKDIR /project
 ---> Running in ea3a89875300
Removing intermediate container ea3a89875300
 ---> d637b4e5abdc
Step 5/9 : COPY cheers.go .
 ---> e87625cc8a98
Step 6/9 : RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o cheers cheers.go
 ---> Running in 46ebb8eae832
Removing intermediate container 46ebb8eae832
 ---> b96addf52dc8
Step 7/9 : FROM scratch
 --->
Step 8/9 : COPY --from=builder /project/cheers /cheers
 ---> 726445b04079
Step 9/9 : ENTRYPOINT ["/cheers"]
 ---> Running in 07124cd1d54f
Removing intermediate container 07124cd1d54f
 ---> 790a722d67bc
Successfully built 790a722d67bc
Successfully tagged hoge/cheers2019:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
  • コンテナ作成
$ docker run -it --rm hoge/cheers2019
the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'

$ winpty docker run -it --rm hoge/cheers2019
  • 成功すると以下のような出力

  • ログイン

$ docker login ; docker push hoge/cheers2019
Authenticating with existing credentials...
Login Succeeded
The push refers to repository [docker.io/hoge/cheers2019]
83bd27c95501: Preparing
83bd27c95501: Pushed
latest: digest: sha256:a2680c711706d56aad980e7d5ae8a1714e62f06bf02e7544d51fa7b740d7c3a1 size: 528

終わり

  • 導入成功

動作確認

遭遇したエラー

エラー1

>docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.

  • どうやらDNSのエラーが有力らしい
  • 初期設定では8.8.8.8に設定されている
  • ipconfig /allで出力されるDNSに変更する
  • この場合172.22.21.21に変更したところエラー解決

>docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:0e11c388b664df8a27a901dce21eb89f11d8292f7fca1b3e3c4321bf7897bffe
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/

エラー2

$ docker login
Authenticating with existing credentials...
Login did not succeed, error: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
Error: Cannot perform an interactive login from a non TTY device
  • これもしばしば遭遇する
  • 認証に失敗しているのかなと思いきや違うらしい
  • いろいろ試したが右下dockerアイコンからRestartしたら治った。。なぜなのかは不明。

エラー3

  • Gitbashでやる場合はホスト側のパス先頭にスラッシュをもう一つつける必要があるらしい
$ docker run --name test-nginx -v /c/Users/hoge/docker-test/html:/usr/share/nginx/html:ro -d -p 8080:80 nginx
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: Mount denied:
The source path "C:/Users/hoge/docker-tutrial/html;C"
doesn't exist and is not known to Docker.
See 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'.
$ docker run --name test-nginx -v //c/Users/hoge/docker-test/html:/usr/share/nginx/html:ro -d -p 8080:80 nginx
7c40c6103be5ad1257d846cf6f349c2e6de1ee29fa008a167556e023c11534a9

エラー4

$ docker create --name test -it alpine /bin/sh
aed6850f35d5a4237abf0768a4f0be9f56737d1930c602a293ab0122b392a9ba

$ docker ps -a
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS                  PORTS               NAMES
aed6850f35d5        alpine               "C:/Program Files/Gi…"   20 seconds ago      Created                                     test

$ docker start test
Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"C:/Program Files/Git/usr/bin/sh\": stat C:/Program Files/Git/usr/bin/sh: no such file or directory": unknown
Error: failed to start containers: test
  • システムデフォルトのshではなく、意図しないGitBash内のshを指定しまうためエラーになるっぽい。。
  • 引数にshを指定せず実行すると成功する
$ which sh
/usr/bin/sh

$ docker create --name test-2 -it alpine
9997f001960caa16326c6a0e2e543660f141b2e913b14efcf4f31916346be3c9

$ docker ps -a
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS                  PORTS               NAMES
9997f001960c        alpine               "/bin/sh"                10 seconds ago      Created                                     test-2
aed6850f35d5        alpine               "C:/Program Files/Gi…"   24 minutes ago      Created                                     test

$ docker start test-2
test-2

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
9997f001960c        alpine              "/bin/sh"           About a minute ago   Up 5 seconds                            test-2



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