docker-compose is unstable using Docker Desktop and WSL2
Description of the issue
In some conditions, some command like docker-compose up or docker-compose ps leads to the following error :
Traceback (most recent call last):
File "bin/docker-compose", line 3, in <module>
File "compose/cli/main.py", line 67, in main
File "compose/cli/main.py", line 123, in perform_command
File "compose/cli/command.py", line 69, in project_from_options
File "compose/cli/command.py", line 125, in get_project
File "compose/cli/command.py", line 184, in get_project_name
File "posixpath.py", line 383, in abspath
FileNotFoundError: [Errno 2] No such file or directory
[3512] Failed to execute script docker-compose
Docker Desktop restart but it doesn't solve the problem.
Context information (for bug reports)
docker-compose.yml
version: '3.8'
services:
mongo:
image: mongo
networks:
mongo_net:
volumes:
- "./mongodata:/data/db"
ports:
- 27017:27017
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: 1234567
command: mongod --bind_ip 0.0.0.0
app:
build:
context: ./app/
dockerfile: app.dockerfile
volumes:
- "./app:/app"
networks:
- mongo_net
entrypoint: python
tty: true
stdin_open: true
depends_on:
- mongo
networks:
mongo_net:
volumes:
mongodata:
app/app.dockerfile
FROM python:3
WORKDIR /app
COPY requirements.txt /requirements.txt
RUN python -m pip install --upgrade pip
RUN pip install --no-cache-dir -r /requirements.txt
WORKDIR /app
WSL2 / Win10 version
> ver
Microsoft Windows [version 10.0.19041.572]
>wsl -l -v
NAME STATE VERSION
* Ubuntu Running 2
docker-desktop Running 2
docker-desktop-data Running 2
Output of docker-compose version
docker-compose version 1.27.4, build 40524192
docker-py version: 4.3.1
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
Output of docker version
Client:
Version: 19.03.8
API version: 1.40
Go version: go1.13.8
Git commit: afacb8b7f0
Built: Wed Oct 14 19:43:43 2020
OS/Arch: linux/amd64
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.0-beta1
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 9c15e82
Built: Tue Oct 13 18:17:18 2020
OS/Arch: linux/amd64
Experimental: true
containerd:
Version: v1.4.1
GitCommit: c623d1b36f09f8ef6536a057bd658b3aa8632828
runc:
Version: 1.0.0-rc92
GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Output of docker-compose config
(Make sure to add the relevant -f and other flags)
Traceback (most recent call last):
File "bin/docker-compose", line 3, in <module>
File "compose/cli/main.py", line 67, in main
File "compose/cli/main.py", line 120, in perform_command
File "compose/cli/main.py", line 324, in config
File "compose/cli/command.py", line 99, in get_config_from_options
File "compose/config/config.py", line 406, in load
File "compose/config/config.py", line 520, in load_services
File "compose/config/config.py", line 501, in build_services
File "compose/config/config.py", line 501, in <listcomp>
File "compose/config/config.py", line 480, in build_service
File "compose/config/config.py", line 289, in with_abs_paths
File "posixpath.py", line 383, in abspath
FileNotFoundError: [Errno 2] No such file or directory
[3611] Failed to execute script docker-compose
Steps to reproduce the issue
I tried many solutions to solve this and now I'm a bit lost. Docker has worked while few months like a charm on an another project. I don't understand what causes that instability. It happens after a docker-compose up. Yesterday, I had this error and tried to reinstall Docker 2.4.0.0 Stable but I had various problem with it (Installer unable to finish its installation, Docker Desktop unstable, Docker service trying to start forever, Stuck when restoring factory default) That was a mess so I removed the previous version of docker and installed the 2.4.2.0 Edge version of Docker Desktop which can be found here.
Docker become more stable after that and I was able to Clean / Purge data then Reset to factory defaults (looks stupid to do that since the installation was fresh but he).
I thought my ordeal was over but this problem come back now.
I have the same issue when running docker-compose inside WSL 2.
Changing docker-compose to docker-compose.exe works for me.
for example:
docker-compose pull
// replace to
docker-compose.exe pull
docker-compose.exe pull
Not work for me
I had the same issue with docker-compose 1.29.1 on AmazonLinux 2.
Error
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'))
The reason for my error was not having the Docker Service up.
Once the Docker Service is started, I could run docker-compose without any issues.
Hope this helps!
I've got similar problems.
- Windows 10 Enterprise
- Docker Desktop: 3.4.0
- WSL Linux: Ubuntu 20.04 LTS
- Docker-Compose: 1.29.2
$ docker-compose -f docker-compose.yml -f docker-compose.local.yml down --rmi local
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 146, in get_project
File "compose/cli/command.py", line 206, in get_project_name
File "posixpath.py", line 383, in abspath
FileNotFoundError: [Errno 2] No such file or directory
[24510] Failed to execute script docker-compose
But I try docker compose command instead of docker-compose, I solved.
$ docker compose -f docker-compose.yml -f docker-compose.local.yml down --rmi local
[+] Running 3/3
...
Whenever this happens to me, changing directory fixes it (locally, temporarily). Literally cd'ing up one level and back down again allows the docker-compose command to run.
@ecwootten I've found cd $PWD to fix the problem as well in one step.
After experiencing this issue for many months, I don't think this is a a problem in docker-compose, but rather a problem in WSL2. I've also experienced similar issues when using git, which I think is due to how the files are mounted in WSL2.
On windows I've got the same error occasionally in Windows Terminal. Just run the same command in new tab helps me. I don't understand why.
same here
I am working on WSL2 and have Docker Desktop installed on Windows 10. All of a sudden, for no reason, I got this error.
sudo apt install docker-compose
This command worked for me.
You may try the following as well:
sudo apt update
sudo apt install docker-compose
this not a solution, you are just installing another docker-compose...
same here
Same issue here
issuing this:
cd .
fixes it for me...
issuing this:
cd .fixes it for me...
It's so silly how simple this fix is. Worked for me
cd ${PWD}
worked for me. following the issue.
$ docker version
Client: Docker Engine - Community
Cloud integration: 1.0.17
Version: 20.10.8
API version: 1.41
Go version: go1.16.6
Git commit: 3967b7d
Built: Fri Jul 30 19:54:02 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.8
API version: 1.41 (minimum version 1.12)
Go version: go1.16.6
Git commit: 75249d8
Built: Fri Jul 30 19:52:10 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.9
GitCommit: e25210fe30a0a703442421b0f60afac609f950a3
runc:
Version: 1.0.1
GitCommit: v1.0.1-0-g4144b63
docker-init:
Version: 0.19.0
GitCommit: de40ad0
docker-compose version
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
wsl2, debian
I've experiencing the same behaviour here.
cd . does solve it temporarly.
I'm working from a mountpoint
Same issue here, cd . seems to fix it
Same here when using WSL 2.
I've fixed it with cd ${PWD} or you could do it as others said with cd ..
It's a weird problem, but it looks like it's from the WSL mounting system.
I used sudo docker-compose down and I was able to run the command docker-compose down successfully. So just add sudo.
I've solved with 'wsl --shutdown' to stops wsl and then started again...