docker-composeでNo such file or directoryになって試行錯誤した話(一応解決)
やたらめったら紆余曲折したので備忘的に残します。
- 手元のPCでコンテナ作成したことありDocker Desktop 2.3.0.3 + WSL1が入っている
- export DOCKER_HOST=tcp://localhost:2375 し忘れている
- なぜかdocker versionでサーバ情報が返ってこない
といった状況のポンコツによる記録になります。
(ホスト名とかは見られたくなかったので適当に置き換えています)
dockerの勉強がしたくて
を見ながら下記のcomposeを行ったところversion: '2'
services:
db:
image: mysql
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
No such file or directoryと出てしまいました。
konny@localhost:/mnt/c/private/container/localenv_d4x$ docker-compose up -d
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.6/http/client.py", line 1281, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1327, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1276, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1042, in _send_output
self.send(msg)
File "/usr/lib/python3.6/http/client.py", line 980, in send
self.connect()
File "/usr/local/lib/python3.6/dist-packages/docker/transport/unixconn.py", line 43, in connect
sock.connect(self.unix_socket)
FileNotFoundError: [Errno 2] No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3/dist-packages/six.py", line 692, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.6/http/client.py", line 1281, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1327, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1276, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1042, in _send_output
self.send(msg)
File "/usr/lib/python3.6/http/client.py", line 980, in send
self.connect()
File "/usr/local/lib/python3.6/dist-packages/docker/transport/unixconn.py", line 43, in connect
sock.connect(self.unix_socket)
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/docker/api/client.py", line 205, in _retrieve_server_version
return self.version(api_version=False)["ApiVersion"]
File "/usr/local/lib/python3.6/dist-packages/docker/api/daemon.py", line 181, in version
return self._result(self._get(url), json=True)
File "/usr/local/lib/python3.6/dist-packages/docker/utils/decorators.py", line 46, in inner
return f(self, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/docker/api/client.py", line 228, in _get
return self.get(url, **self._set_request_timeout(kwargs))
File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 543, in get
return self.request('GET', url, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/docker-compose", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/dist-packages/compose/cli/main.py", line 67, in main
command()
File "/usr/local/lib/python3.6/dist-packages/compose/cli/main.py", line 123, in perform_command
project = project_from_options('.', options)
File "/usr/local/lib/python3.6/dist-packages/compose/cli/command.py", line 69, in project_from_options
environment_file=environment_file
File "/usr/local/lib/python3.6/dist-packages/compose/cli/command.py", line 132, in get_project
verbose=verbose, version=api_version, context=context, environment=environment
File "/usr/local/lib/python3.6/dist-packages/compose/cli/docker_client.py", line 43, in get_client
environment=environment, tls_version=get_tls_version(environment)
File "/usr/local/lib/python3.6/dist-packages/compose/cli/docker_client.py", line 170, in docker_client
client = APIClient(**kwargs)
File "/usr/local/lib/python3.6/dist-packages/docker/api/client.py", line 188, in __init__
self._version = self._retrieve_server_version()
File "/usr/local/lib/python3.6/dist-packages/docker/api/client.py", line 213, in _retrieve_server_version
'Error while fetching server API version: {0}'.format(e)
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
ファイルがない・・・?
似たようなエラーをググると何故か権限について言及している人がいて
を実施
でもエラー内容に変化はない
念のため
konny@localhost:/mnt/c/private/container/localenv_d4x$ docker-compose version
docker-compose version 1.27.4, build unknown
docker-py version: 4.3.1
CPython version: 3.6.9
OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
konny@localhost:/mnt/c/private/container/localenv_d4x$
そこまで古いわけではなさそうだ。
dockerのアプリを再起動してみるも状況に変化はない
更地にymlだけ置きなおして再度実行しても変わらない。
一応コマンドでapt-getしてみる
が変わらなかった
konny@localhost::/mnt/c/private/container/test_container$ sudo apt install docker-compose
konny@localhost::/mnt/c/private/container/test_container$ docker-compose version
docker-compose version 1.27.4, build unknown
docker-py version: 4.3.1
CPython version: 3.6.9
OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
konny@localhost:/mnt/c/private/container/test_container$
下記を参考に最新化しなおしてみる
konny@localhost:/mnt/c/private/container/test_container$ docker-compose version
docker-compose version 1.27.4, build unknown
docker-py version: 4.3.1
CPython version: 3.6.9
OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
konny@localhost:/mnt/c/private/container/test_container$ ls -l /usr/local/bin/docker-compose
-rwxr-xr-x 1 root root 215 Oct 15 2020 /usr/local/bin/docker-compose
konny@localhost:/mnt/c/private/container/test_container$ sudo rm -rf docker-compose
konny@localhost:/mnt/c/private/container/test_container$ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 633 100 633 0 0 2096 0 --:--:-- --:--:-- --:--:-- 2089
100 12.1M 100 12.1M 0 0 10.9M 0 0:00:01 0:00:01 --:--:-- 10.9M
konny@localhost:/mnt/c/private/container/test_container$ sudo chmod +x /usr/local/bin/docker-compose
konny@localhost:/mnt/c/private/container/test_container$ docker-compose -v
docker-compose version 1.29.1, build c34c88b2
konny@localhost:/mnt/c/private/container/test_container$ docker-compose version
docker-compose version 1.29.1, build c34c88b2
docker-py version: 5.0.0
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
konny@localhost:/mnt/c/private/container/test_container$
再度実行するけど
エラー文が見やすくなっただけで言っていることは変わらなかった
konny@localhost:/mnt/c/private/container/test_container$ docker-compose up -d
Traceback (most recent call last):
File "urllib3/connectionpool.py", line 677, in urlopen
File "urllib3/connectionpool.py", line 392, in _make_request
File "http/client.py", line 1277, in request
File "http/client.py", line 1323, in _send_request
File "http/client.py", line 1272, in endheaders
File "http/client.py", line 1032, in _send_output
File "http/client.py", line 972, in send
File "docker/transport/unixconn.py", line 43, in connect
FileNotFoundError: [Errno 2] No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "requests/adapters.py", line 449, in send
File "urllib3/connectionpool.py", line 727, in urlopen
File "urllib3/util/retry.py", line 410, in increment
File "urllib3/packages/six.py", line 734, in reraise
File "urllib3/connectionpool.py", line 677, in urlopen
File "urllib3/connectionpool.py", line 392, in _make_request
File "http/client.py", line 1277, in request
File "http/client.py", line 1323, in _send_request
File "http/client.py", line 1272, in endheaders
File "http/client.py", line 1032, in _send_output
File "http/client.py", line 972, in send
File "docker/transport/unixconn.py", line 43, in connect
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "docker/api/client.py", line 214, in _retrieve_server_version
File "docker/api/daemon.py", line 181, in version
File "docker/utils/decorators.py", line 46, in inner
File "docker/api/client.py", line 237, in _get
File "requests/sessions.py", line 543, in get
File "requests/sessions.py", line 530, in request
File "requests/sessions.py", line 643, in send
File "requests/adapters.py", line 498, in send
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "docker-compose", line 3, in <module>
File "compose/cli/main.py", line 81, in main
File "compose/cli/main.py", line 200, in perform_command
File "compose/cli/command.py", line 70, in project_from_options
File "compose/cli/command.py", line 153, in get_project
File "compose/cli/docker_client.py", line 43, in get_client
File "compose/cli/docker_client.py", line 170, in docker_client
File "docker/api/client.py", line 197, in __init__
File "docker/api/client.py", line 222, in _retrieve_server_version
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
[9582] Failed to execute script docker-compose
konny@localhost:/mnt/c/private/container/test_container$
dockerデーモンの状態が悪いのか?と思いやってみたけど変わらない
そもそも何度もリスタートしているんだから関係ないよねえ・・・
WSL1なのが悪いのか?
Dockerアプリが古いのが良くないのか?
更新はしてみたいけど、
仕事で使っているので変更するのはどきどきする。
まだまだ終わらない
単発のコマンドを叩くと、アプリとCLIで見てるsockが違う?
konny@localhost:/mnt/c/Private/container/test_container$ docker run -dp 80:80 docker/getting-started
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
仕切り直して、dockerdaemonが起動できていないようなのでそれっぽいコマンドで立ち上げてみるが、
スタートしたと表示されるのに相変わらずサーバはいない。
何が起動できたのかよくわからない。
konny@localhost:/mnt/c/Private/container/test_container$ sudo service docker start
[sudo] password for kana-k:
* Starting Docker: docker [ OK ]
konny@localhost:/mnt/c/Private/container/test_container$ docker version
Client: Docker Engine - Community
Version: 20.10.5
API version: 1.41
Go version: go1.13.15
Git commit: 55c4c88
Built: Tue Mar 2 20:18:05 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
じゃあそもそもいないのか?
aptで持ってこれるかしら→だめ。WSL古いせいかな・・・・
konny@localhost:/mnt/c/Private/container/test_container$ sudo apt install docker.io
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
docker.io : Depends: containerd (>= 1.2.6-0ubuntu1~)
E: Unable to correct problems, you have held broken packages.
konny@localhost:/mnt/c/Private/container/test_container$
じゃあWSL1ではどうやってDocker使うのよって話
そういえば確かにそんな設定入れていた・・・・
- タスクトレイアイコンの Docker を右クリック → Settings から設定を開く
- □ Expose daemon on tcp://localhost:2375 without TLS にチェックを入れる
- DOCKER_HOST 環境変数を Docker for Windows に向ける
export DOCKER_HOST=tcp://localhost:2375
ゴンお前だったのか
いつもdocker daemonを動かしてくれていたのは(スクリプトにぶっこんであるためすっかり失念していた)
konny@localhost:/mnt/c/Private/container/test_container$ export DOCKER_HOST=tcp://localhost:2375
konny@localhost:/mnt/c/Private/container/test_container$ docker version
Client: Docker Engine - Community
Version: 20.10.5
API version: 1.40
Go version: go1.13.15
Git commit: 55c4c88
Built: Tue Mar 2 20:18:05 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 19.03.8
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:29:16 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
konny@localhost:/mnt/c/Private/container/test_container$
というわけで再実行したらエラー吐きつつ起動している風なログが!
変わらずエラーではあるもののDBの起動には成功している様子。
あとはyamlとかPATHの見直しで済みそうだ🙌
konny@localhost:/mnt/c/Private/container/test_container$ docker-compose up
WARNING: Found orphan containers (test_container_myalpine_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Pulling db (mysql:)...
latest: Pulling from library/mysql
b380bbd43752: Pull complete
f23cbf2ecc5d: Pull complete
30cfc6c29c0a: Pull complete
b38609286cbe: Pull complete
8211d9e66cd6: Pull complete
2313f9eeca4a: Pull complete
7eb487d00da0: Pull complete
4d7421c8152e: Pull complete
77f3d8811a28: Pull complete
cce755338cba: Pull complete
69b753046b9f: Pull complete
b2e64b0ab53c: Pull complete
Digest: sha256:6d7d4524463fe6e2b893ffc2b89543c81dec7ef82fb2020a1b27606666464d87
Status: Downloaded newer image for mysql:latest
Building web
free(): invalid pointer
SIGABRT: abort
PC=0x7f843c64ef47 m=0 sigcode=18446744073709551610
signal arrived during cgo execution
goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4afd50, 0xc420055cc0, 0xc420055ce8)
/usr/lib/go-1.8/src/runtime/cgocall.go:131 +0xe2 fp=0xc420055c90 sp=0xc420055c50
github.com/docker/docker-credential-helpers/secretservice._Cfunc_free(0x1df69a0)
github.com/docker/docker-credential-helpers/secretservice/_obj/_cgo_gotypes.go:111 +0x41 fp=0xc420055cc0 sp=0xc420055c90
github.com/docker/docker-credential-helpers/secretservice.Secretservice.List.func5(0x1df69a0)
/build/golang-github-docker-docker-credential-helpers-cMhSy1/golang-github-docker-docker-credential-helpers-0.5.0/obj-x86_64-linux-gnu/src/github.com/docker/docker-credential-helpers/secretservice/secretservice_linux.go:96 +0x60 fp=0xc420055cf8 sp=0xc420055cc0
github.com/docker/docker-credential-helpers/secretservice.Secretservice.List(0x0, 0x756060, 0xc420014360)
/build/golang-github-docker-docker-credential-helpers-cMhSy1/golang-github-docker-docker-credential-helpers-0.5.0/obj-x86_64-linux-gnu/src/github.com/docker/docker-credential-helpers/secretservice/secretservice_linux.go:97 +0x217 fp=0xc420055da0 sp=0xc420055cf8
github.com/docker/docker-credential-helpers/secretservice.(*Secretservice).List(0x77e548, 0xc420055e88, 0x410022, 0xc4200142c0)
<autogenerated>:4 +0x46 fp=0xc420055de0 sp=0xc420055da0
github.com/docker/docker-credential-helpers/credentials.List(0x756ba0, 0x77e548, 0x7560e0, 0xc42000e018, 0x0, 0x10)
/build/golang-github-docker-docker-credential-helpers-cMhSy1/golang-github-docker-docker-credential-helpers-0.5.0/obj-x86_64-linux-gnu/src/github.com/docker/docker-credential-helpers/credentials/credentials.go:145 +0x3e fp=0xc420055e68 sp=0xc420055de0
github.com/docker/docker-credential-helpers/credentials.HandleCommand(0x756ba0, 0x77e548, 0x7fffffa0fe77, 0x4, 0x7560a0, 0xc42000e010, 0x7560e0, 0xc42000e018, 0x40e398, 0x4d35c0)
/build/golang-github-docker-docker-credential-helpers-cMhSy1/golang-github-docker-docker-credential-helpers-0.5.0/obj-x86_64-linux-gnu/src/github.com/docker/docker-credential-helpers/credentials/credentials.go:60 +0x16d fp=0xc420055ed8 sp=0xc420055e68
github.com/docker/docker-credential-helpers/credentials.Serve(0x756ba0, 0x77e548)
/build/golang-github-docker-docker-credential-helpers-cMhSy1/golang-github-docker-docker-credential-helpers-0.5.0/obj-x86_64-linux-gnu/src/github.com/docker/docker-credential-helpers/credentials/credentials.go:41 +0x1cb fp=0xc420055f58 sp=0xc420055ed8
main.main()
/build/golang-github-docker-docker-credential-helpers-cMhSy1/golang-github-docker-docker-credential-helpers-0.5.0/secretservice/cmd/main_linux.go:9 +0x4f fp=0xc420055f88 sp=0xc420055f58
runtime.main()
/usr/lib/go-1.8/src/runtime/proc.go:185 +0x20a fp=0xc420055fe0 sp=0xc420055f88
runtime.goexit()
/usr/lib/go-1.8/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc420055fe8 sp=0xc420055fe0
goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/lib/go-1.8/src/runtime/asm_amd64.s:2197 +0x1
rax 0x0
rbx 0x7fffffa0f8c0
rcx 0x8
rdx 0x0
rdi 0x2
rsi 0x7fffffa0f650
rbp 0x7fffffa0f9c0
rsp 0x7fffffa0f650
r8 0x0
r9 0x7fffffa0f650
r10 0x8
r11 0x8
r12 0x7fffffa0f8c0
r13 0x1000
r14 0x0
r15 0x30
rip 0x7f843c64ef47
rflags 0x246
cs 0x33
fs 0x53
gs 0x2b
Sending build context to Docker daemon 3.072kB
Step 1/3 : FROM alpine
---> 14119a10abf4
Step 2/3 : RUN apk add bash procps curl
---> Using cache
---> 7db8f8645046
Step 3/3 : CMD sh -c "(while :; do date; sleep 1; done) >&2"
---> Using cache
---> 22605e0d9f68
Successfully built 22605e0d9f68
Successfully tagged test_container_web:latest
WARNING: Image for service web was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating test_container_db_1 ... done
Creating test_container_web_1 ... error
ERROR: for test_container_web_1 Cannot start service web: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"bundle\": executable file not found in $PATH": unknown
ERROR: for web Cannot start service web: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"bundle\": executable file not found in $PATH": unknown
ERROR: Encountered errors while bringing up the project.
Discussion