268

I want to install this module but there is something wrong when I try the step docker-compose build ...

I tried to update the Docker version and restart Docker many times. But it didn't work.

git clone https://github.com/uhh-lt/158.git
cd 158
docker-compose build
File "/home/ming/.local/bin/docker-compose", line 8, in <module>
    sys.exit(main())
  File "/home/ming/.local/lib/python3.8/site-packages/compose/cli/main.py", line 67, in main
    command()
  File "/home/ming/.local/lib/python3.8/site-packages/compose/cli/main.py", line 123, in perform_command
    project = project_from_options('.', options)
  File "/home/ming/.local/lib/python3.8/site-packages/compose/cli/command.py", line 60, in project_from_options
    return get_project(
  File "/home/ming/.local/lib/python3.8/site-packages/compose/cli/command.py", line 131, in get_project
    client = get_client(
  File "/home/ming/.local/lib/python3.8/site-packages/compose/cli/docker_client.py", line 41, in get_client
    client = docker_client(
  File "/home/ming/.local/lib/python3.8/site-packages/compose/cli/docker_client.py", line 170, in docker_client
    client = APIClient(**kwargs)
  File "/home/ming/.local/lib/python3.8/site-packages/docker/api/client.py", line 188, in __init__
    self._version = self._retrieve_server_version()
  File "/home/ming/.local/lib/python3.8/site-packages/docker/api/client.py", line 212, in _retrieve_server_version
    raise DockerException(
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

Update 2020-11-23

Thanks for two of you helping me with the error! I tried the commend but can't connect to my Docker:

ming@KITM-7664:~$ sudo /etc/init.d/docker start
[sudo] password for ming:
 * Starting Docker: docker                                                                                       [ OK ]

ming@KITM-7664:~$ which docker
/usr/bin/docker

ming@KITM-7664:~$ docker version
Client: Docker Engine - Community
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46d9d
 Built:             Wed Sep 16 17:02:52 2020
 OS/Arch:           linux/amd64
 Experimental:      false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

ming@KITM-7664:~$ systemctl status docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

ming@KITM-7664:~$ systemctl start docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

ming@KITM-7664:~$ sudo /etc/init.d/docker start
 * Starting Docker: docker                                                                                       [ OK ]

ming@KITM-7664:~$ docker version
Client: Docker Engine - Community
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46d9d
 Built:             Wed Sep 16 17:02:52 2020
 OS/Arch:           linux/amd64
 Experimental:      false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
2
  • 69
    make sure that docker desktop is up running. In my case I got docker.errors.DockerException: Error while fetching server API version: (2, 'CreateFile', 'The system cannot find the file specified.') because I manually stopped docker desktop. Once I restarted it, everthing worked as expected. Commented Feb 1, 2021 at 20:42
  • 1
    In addition to What @YJDev said, I installed docker-desktop, which I guess takes over starting the docker service. So once I started up docker-desktop, docker-compose ran like a charm! Commented May 11, 2022 at 16:44

31 Answers 31

377

Are you sure docker is running on your system? You can get that error when compose is not able to connect to docker via docker socket (if any other way for connection is not defined).

If you are running on linux, usually you can run systemctl status docker to check if docker daemon is running and systemctl start docker to start it.

It would help to tell what OS and docker version are you using.

Sign up to request clarification or add additional context in comments.

10 Comments

I understand. It sounds a bit like WSL... please try "sudo service docker start" and see if it's working. This is in case it's WSL, have you tried to start it as administrator (by right clicking from start menu)?
"sudo service docker start" didn't work so I opened the windows powershell(administrator), run "docker-compose build " and the other error happened'/usr/bin/env: ‘python3\r’: No such file or directory ERROR: Service 'frontend' failed to build : The command '/bin/sh -c ./frontend_assets.py' returned a non-zero code: 127'
Yes, until docker daemon does not start (the "sudo service docker start" supposed to do that), the socket file doesn't exists and docker and compose cannot connect to the daemon. First thing you should do is find out why docker daemon doesn't start. Please try and follow the informations here (including trying to run dockerd manually and also see the troubleshooting guide on the same page): docs.docker.com/config/daemon
Wonder why isn't this upvoted more? Should be a common error and this was the spot-on answer.
Saw this error. Panicked. Saw this response. Calm.
|
128

set the permission like this,

sudo chmod 666 /var/run/docker.sock

7 Comments

Be careful! Anyone who can access the Docker socket can pretty trivially root the host. This setting can make sense on a developer system where you give yourself unrestricted sudo access anyways, but it may not be good security practice in other contexts.
Could you explain why this works?
Bad suggestion, downvoted. The socket file will have a group – usually docker. You should add yourself to that group (add your username to the group in /etc/group, log out, log in again) if you want to have access to the socket. Opening it up to all users of the machine like this is bad practice, for reasons that @DavidMaze already pointed out.
@DanielWalker it works because it gives all users access to the "socket" file – the three digits in the chmod command stand for user permissions, group permissions, world permissions and all three are set to 6 which means "read and write". The socket file is a channel for communicating with the Docker process, similar to a network port. Without access to this socket, you can't communicate with the Docker process (daemon). However, giving access to a particular user (you) by giving access to everyone is like removing a door entirely instead of giving someone a key to unlock the door.
This is a safer first try stackoverflow.com/a/68968809/363217
|
57

If you are seeing this in May of 2024, this is likely a result of an issue with a new release of Python's request library (2.32.0). At the time of this writing, there's a pull request to fix this, but until it is merged, this issue can be resolved by downgrading the requests library to below 2.32.0: pip3 install requests==2.31.0

5 Comments

how do you get around the 'externally managed environment' message that gets thrown with newer versions of python/pip?
There was another problem that I needed to solve and I needed to go to install requests==2.29.0 The issue that I was having was request() got an unexpected keyword argument 'chunked' when using docker from python
June 2024 - workaround is to downgrade to pip3 install requests==2.29.0! Downgrade to 2.31.0 didn't help for me today :(
@Dan as it mentions in the message you can use (risky but works) --break-system-packages
Dec 2024 - pip3 install requests==2.31.0 solved error message docker.errors.DockerException: Error while fetching server API version: Not supported URL scheme http+docker
43

When you are using WSL (Windows Subsystem for Linux), you need to enable 'WSL Integration' for the required distro in Windows Docker Desktop (Settings -> Resources-> WSL Integration -> Enable integration with required distros).

WSL Integration

2 Comments

Actually I already this option set, but I turned it off, reload docker, then turn it on and reload the docker and it did the trick for me.
Make sure it starts with administrator
38

By default, the docker command can only be run the root user or by a user in the docker group, which is automatically created during Docker’s installation process. If you want to avoid typing sudo whenever you run the docker command, add your username to the docker group:

sudo usermod -aG docker ${USER}

To apply the new group membership, log out of the server and back in, or type the following:

su - ${USER}

You will be prompted to enter your user’s password to continue.

4 Comments

This solution actually helped me and seems to be more safe that setting 666 permisions on docker.sock
Didn't work for me, but this worked: stackoverflow.com/questions/64662372/…
how do i create the group?
The group is created during Docker’s installation process.
38

Just changes docker-compose to docker compose. In newer version you should use docker compose up -d instead docker-compose up -d befor this

mkdir -p ~/.docker/cli-plugins/
curl -SL https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose 
chmod +x ~/.docker/cli-plugins/docker-compose
docker compose version

or you can install docker-compose-v2

sudo apt install docker-compose-v2

and then use

docker compose up -d or docker compose build or ...

instead

docker-compose

3 Comments

Worked well after an Ubuntu 22.04 to 24.04 upgrade - all the other solutions wanted to make many python changes.
This was it in my case. I'm using Ubuntu 24.04 LTS upgraded from 22.04 LTS
Thank you very much! Worked for me on Debian 12.
26

I had this issue while starting docker-compose. The problem was caused by `urllib3'. The fix is simple:

pip install 'urllib3<2'

Source: https://github.com/docker/docker-py/issues/3113#issuecomment-1579172104

1 Comment

They've fixed this now so you should be able to upgrade the docker package instead github.com/docker/docker-py/issues/3113 pip install --upgrade docker
18

sudo service docker start or
sudo service docker restart

Comments

13

In macOS with Docker Desktop 4.18, check Enable default docker socket in Settings -> Advanced section.

2 Comments

Confirming that this enabled the Docker SDK for Python on my M1 Mac Ventura 13.3.1 to work. I tested client = docker.from_env() and client = docker.DockerClient(base_url='unix://var/run/docker.sock') and I arrived at a DockerException with Connection Aborted error but now it does execute properly on my system. Docker Desktop Version 4.22.1
I would add that sometimes this option needs to be disabled and re-enabled (restarting Docker won't fix it)
9

Just had the same issue after updating Windows Docker desktop to it's latest version (20.10.2, build 2291f61). It happened that this update disabled the WSL2 integration with my virtual Ubuntu 18.04, which I use to run most projects.

I solved it this way:

  1. Open Docker Desktop
  2. Go to Settings > Resources > WSL Integration
  3. Make sure that your distribution is enabled
  4. Restart Docker
  5. Without the need of restarting WSL2, docker should work again

Docker Desktop distro integration

Comments

8

You don't have permission to use the docker socket, by default only the docker group can access it. You can verify this with ls -l /var/run/docker.sock, which will print something like:

srw-rw----. 1 root docker 0 Oct  4 18:04 /var/run/docker.sock

To be able to access the socket and use Docker, add yourself to the Docker group with the following command:

sudo usermod -a -G docker $(whoami)

Then logout and back in. Docker will now work.

Comments

6

I had a similar issue and it turned out to be due to Docker server not running. I started the app and then ran docker-compose up and it started working fine. Hope it helps anyone who's caught in a similar situation. :-)

1 Comment

how do you start docker server? Ubuntu server
6

Make sure you check the box for 'use Docker Compose V2'. It solved for me. docker desktop

1 Comment

This can be found in Settings -> General -> User Docker Compose V2 -> Apply and Restart
6

I have no idea the cause of error but reinstalling requests and urllib3 worked for me.

pip install --force-reinstall 'requests<2.29.0' 'urllib3<2.0'

Comments

6

Please make sure you have docker compose v2 by using the command:

sudo apt install docker-compose-v2

After that, you can run start docker compose by navigating to the appropriate directory where your docker-compose.yaml file exists and running:

docker compose up -d

1 Comment

Instead of using sudo docker-compose up -d , I used sudo docker compose up -d
4

If you're using docker-compose inside podman try the below command to resolve this issue "docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))"

systemctl start podman.socket

3 Comments

You can use user socket systemctl --user start podman.socket instead of system socket. Also be sure to do export DOCKER_HOST=unix://$XDB_RUNTIME_DIR/podman/podman.sock. Check this for details.
Thanks, but note, there's a typo. It should be XDG not XDB. I have been both saved and burned by your comment multiple times :)
And systemctl [--user] enable podman.socket if you wish for this to persist across restarts.
2

At Linux (at least Ubuntu 18.04.x), you sometimes need to log out and re-login your X user session. Logging out of bash or out of the terminal window and re-logging in is not enough, see for example https://askubuntu.com/questions/1161020/groups-and-groups-user-show-different-groups-dialout-is-missing

Comments

2

In Mac OS and Windows sometimes that's enough to start up docker application and this error is because of loss of docker daemon in system.

Comments

2

My issue was I was not signed into docker desktop.

Comments

2

I had this error running docker compose in Linux Subsystem on Win10, the problem was that I have forgotten to start Docker Desktop application

Comments

2

On MacOS I installed XCode after Docker (Docker Desktop). Afterwards my Python App (testcontainers) was unable to communicate to Docker (stopped working). Running /Applications/Docker.app/Contents/MacOS/uninstall and open Docker again fixed it for me on M1 MacBook. (Removes config, images, ...)

Comments

2

I had this problem while using ubuntu 22.04 wsl on windows and then I solve it like this

sudo update-alternatives --config iptables

it will show something like this

 Selection    Path                       Priority   Status
------------------------------------------------------------
  0            /usr/sbin/iptables-nft      20        auto mode
* 1            /usr/sbin/iptables-legacy   10        manual mode
  2            /usr/sbin/iptables-nft      20        manual mode

then press 1

Press <enter> to keep the current choice[*], or type selection number: 1

Start docker using services

sudo service docker start

Comments

2

I'm also get this error when i try to run the docker-compose and docker desktop is turn off, i think that is bug in docker-compose that not notify the user it that the problem is becuse the docker service is down, same as the docker cli that throw correct error:

C:\Users\x\IdeaProjects\mongo-exmple>docker pull node
Using default tag: latest
error during connect: This error may indicate that the docker daemon is not running.: Post "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/images/create?fromImage=node&tag=latest": open //./pipe/docker_engine: The system cannot find 
the file specified.

Comments

2

I ran into this same issue on my Macbook Pro.

docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

I finally fixed it by flipping on the setting Allow the default Docker socket to be used (requires password) in Docker Desktop -> Settings -> Advanced.

Comments

1

I had this happen on a Mac after doing an OS update.

I was able to run docker on the command line but Docker Desktop wasn't running - starting Docker Desktop up fixed the issue.

Comments

1

On macOS, deleting Docker's data has worked for me:

rm -rf ~/Library/Containers/com.docker.*

It's a crude solution, and I wouldn't recommend if you have any precious data in your local docker install.

Comments

0

In Windows exiting from Docker and running it again sometimes helps. Apparently not always docker starts up properly.

1 Comment

For me it was related to enabled corporate VPN. I disabled it and then docker started up successfully....
0

try to run your command with sudo.

Comments

0

I was using Ubuntu version 24 and I had this error. I changed to version 22 and the problem was solved.

Comments

0

Had the same problem on newly installed ubuntu 24. If you feel the issue is about compatibility with python packages a possible and natural solution is to install docker from the docker package instead of the ubuntu one. Follow instructions on the docker site. Worked without issues for me and provided the latest version: docker-compose is now a plugin of docker and you use it with docker compose instead of docker-compose.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.