IT박스

docker-compose에서 docker에 연결할 수 없습니다

itboxs 2020. 7. 8. 08:07
반응형

docker-compose에서 docker에 연결할 수 없습니다


Mac OS 10.8.5에 docker-machine 0.1.0 및 docker-compose 1.1.0을 설치했습니다.
Docker-machine이 정상적으로 실행 중이며 docker-machine ssh로 연결할 수 있습니다.

$ docker-machine ls
NAME   ACTIVE   DRIVER       STATE     URL                         SWARM
dev    *        virtualbox   Running   tcp://192.168.99.100:2376   

그러나 docker-compose에서 연결할 수 없습니다.

$ docker-compose up

http + unix : //var/run/docker.sock에서 Docker 데몬에 연결할 수 없습니다-실행 중입니까?

비표준 위치에있는 경우 DOCKER_HOST 환경 변수를 사용하여 URL을 지정하십시오.

내 Dockerfile과 docker-compose.yml이 여기 있습니다.

도커 파일

FROM centos:centos7
DOCKER_HOST tcp://192.168.99.100:2376

docker-compose.yml

web:
  build: .

왜 연결할 수 없습니까? 어떤 아이디어?


Docker 머신이 실행 중입니다. 그러나 Docker 시스템에 연결하려면 일부 환경을 내 보내야합니다. 기본적으로 dockerCLI 클라이언트는 http+unix://var/run/docker.sock(오류 메시지에 표시된대로)를 사용하여 데몬과 통신하려고합니다 .

를 사용하여 올바른 환경 변수를 내 보낸 eval $(docker-machine env dev)다음 다시 시도하십시오. docker-machine env dev내보낼 환경 변수를 확인하기 위해 실행할 수도 있습니다 . DOCKER_HOST오류 메시지에서 설정해야 할 수도 있듯이 그 중 하나는 입니다.


나를위한 간단한 해결책 : sudo docker-compose up


업데이트 2016-3-14 : docker 설치 프로세스 (또는 docker-compose?)의 어느 시점에서 사용자 이름을 "docker"그룹에 추가하는 제안과 예가 있습니다. 이렇게하면 다음과 같이 모든 docker 명령 앞에 "sudo"가 필요하지 않습니다.

~ > docker run -it ubuntu /bin/bash
root@665d1ea76b8d:/# date
Mon Mar 14 23:43:36 UTC 2016
root@665d1ea76b8d:/# exit
exit
~ > 

설치 명령의 출력 (docker-compose의 docker & 2nd install)을주의 깊게 살펴보면 필요한 단계를 찾을 수 있습니다. https://subosito.com/posts/docker-tips/ 에도 나와 있습니다.

Sudo? 아니!

명령을 실행할 때마다 sudo docker를 입력하는 데 지치셨습니까? 그래, 그것을 처리하는 방법이 있습니다. 도커에는 당연히 루트 사용자가 필요하지만 도커 작업에 루트와 동등한 그룹을 제공 할 수 있습니다.

docker라는 그룹을 만든 다음 원하는 사용자를 해당 그룹에 추가 할 수 있습니다. 도커 서비스를 다시 시작한 후 사용자는 도커 작업을 수행 할 때마다 sudo를 입력 할 필요가 없습니다. 쉘 명령에서 어떻게 보입니까? 루트로 여기에 당신은 간다 :

> sudo groupadd docker
> sudo gpasswd -a username docker
> sudo service docker restart 

끝난!

2017-3-9 업데이트

Docker 설치 지침이 여기에 업데이트되었습니다.

Linux의 설치 후 단계

이 섹션에는 Docker에서 더 잘 작동하도록 Linux 호스트를 구성하기위한 선택적 절차가 포함되어 있습니다.

Docker를 루트가 아닌 사용자로 관리

docker 데몬은 TCP 포트 대신 Unix 소켓에 바인딩됩니다. 기본적으로 Unix 소켓은 사용자 루트가 소유하고 다른 사용자는 sudo를 통해서만 액세스 할 수 있습니다. docker 데몬은 항상 루트 사용자로 실행됩니다.

docker 명령을 사용할 때 sudo를 사용하지 않으려면 docker라는 Unix 그룹을 만들고 사용자를 추가하십시오. docker 데몬이 시작되면 docker 그룹에서 Unix 소켓의 소유권을 읽고 쓸 수 있습니다.

도커 그룹을 만들고 사용자를 추가하려면 :

# 1. Create the docker group.
$ sudo groupadd docker

# 2. Add your user to the docker group.
$ sudo usermod -aG docker $USER

# 3. Log out and log back in so that your group membership is re-evaluated.

# 4. Verify that you can run docker commands without sudo.
$ docker run hello-world

이 명령은 테스트 이미지를 다운로드하여 컨테이너에서 실행합니다. 컨테이너가 실행될 때 정보 메시지를 인쇄하고 종료합니다.


를 사용하여 docker를 시작한 경우 Like sudo와 함께 docker-compose up을 실행해야합니다 sudo.sudo docker-compose up


By default the docker daemon always runs as the root user, therefore you need to prepend sudo to your Docker command(s).

If you don’t want to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.

To create the docker group and add your user:

  1. Create the docker group.

    $ sudo groupadd docker

  2. Add your user to the docker group.

    $ sudo usermod -aG docker $USER

  3. Log out and log back in so that your group membership is re-evaluated.

  4. Verify that you can docker commands without sudo.

    $ docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

The steps outlined above comes from the official Docker documentation.


sudo systemctl start docker - to start the Docker service.

sudo docker-compose up after that.

I have Fedora 26, and trying to solve the same issue I eventually entered Docker Compose on Fedora Developers' page and then Docker on Fedora Developers' page, which helped me.

Probably, docker service considered by community to start with the system and run in background all the time, but for me it was not so obvious, and that's the reason I can think of why there's no popular answer like this one.

On the Fedora Developers' page there's instruction how to enable Docker to start with the system:

sudo systemctl enable docker


If you are on Linux you may not have docker-machine installed since it is only installed by default on Windows and Mac computers.

If so you will need to got to: https://docs.docker.com/machine/install-machine/ to find instructions for how to install it on your version of Linux.

After installing, retry running docker-compose up before trying anything listed above.

Hope this helps someone. This worked for my devilbox installation in Fedora 25.


if you are using docker-machine then you have to activate the environment using env variable. incase you are not using docker-machine then run your commands with sudo


Answer from @srfrnk works for me.

In my situation, I had the next docker-compose.yml file:

  nginx:
    build:
      context: ./
      dockerfile: "./docker/nginx.staging/Dockerfile"
    depends_on:
      - scripts
    environment:
      NGINX_SERVER_NAME: "some.host"
      NGINX_STATIC_CONTENT_OPEN_FILE_CACHE: "off"
      NGINX_ERROR_LOG_LEVEL: debug
      NGINX_BACKEND_HOST: scripts
      NGINX_SERVER_ROOT: /var/www/html
    volumes:
      - ./docker-runtime/drupal/files:/var/www/html/sites/default/files:rw
    ports:
      - 80:80

./docker-runtime owner and group - is root when the other files owner - my user. When I tried to build nginx

Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?

I added ./docker-runtime to .dockerignore and it is solved my problem.


Anyone checked log ?

In my case error message in /var/log/upstart/docker.log was:

Listening for HTTP on unix (/var/run/docker.sock) 
[graphdriver] using prior storage driver "aufs" 
Running modprobe bridge nf_nat failed with message: , error: exit status 1 
Error starting daemon: Error initializing network controller: Error creating default "bridge" network: can't find an address range for interface "docker0" 

Worth to mentioned I had vpn turned on, so: $ sudo service openvpn stop $ sudo service docker restart $ docker-compose up|start $ sudo service openvpn start was the solution.


I've had the same symptoms.

Only diff that it happened only during docker-compose build docker ps worked. Happened with version 2.x as well as 3.x. Restarted docker service, then the machine... Even re-installed docker + docker-compose.

Tried everything but nothing helped.

Finally I tried building the Dockerfile "manually" by using docker build.

Apparently I had a permission issue on a file/folder inside the Docker context. It was trying to read the context when starting the build and failed with a proper error message. However this error message did not propagate to docker-compose which only shows Couldn't connect to Docker daemon at http+unix://var/run/docker.sock - is it running?

Having found that the solution was simply adding the file/folder to the .dockerignore file since it wasn't needed for the build. Another solution might have been to chown or chmod it.

Anyway maybe this could help someone coming across the same issue that really has nothing to do with docker and the misleading error message being displayed.


Apart from adding users to docker group, to avoid typing sudo repetitively, you can also create an alias for docker commands like so:

alias docker-compose="sudo docker-compose"
alias docker="sudo docker"

For me, I started upgrading Docker and cancelled midway. I didn't notice that Docker was not running (if it was, there is an icon at the top nav bar of my Macbook, by the battery remaining, time, etc). Once I launched it, and finished the upgrade, docker-compose up worked again!


$sudo docker-compose up

I did follow the steps as it is in the above answer to add $USER to group docker. i didn't want to add a new group docker because in my docker installation a group named docker automatically created.

Docker CE is installed and running. The docker group is created but no users are added to it. You need to use sudo to run Docker commands. Continue to Linux postinstall to allow non-privileged users to run Docker commands and for other optional configuration steps.

but using docker-compose up didn't work either. It gave the same previous error. So in my case(Ubuntu 18.10) sudo docker-compose up fixed the issue.

ps: @Tiw thanks for the advice.


try this:

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose


while running docker-compose pull - i was getting below error

ERROR: Couldn't connect to Docker daemon at http+docker://localhost

is it running?

solution -

sudo service docker start 

issue resolved


My setup has got two cases for this error:

  • __pycache__ files created by root user after I run integration tests inside container are inaccessible for docker (tells you original problem) and docker-compose (tells you about docker host ambiguously);
  • microk8s blocked my port until I stopped it.

Try running dockerd or sudo dockerdif required first to start daemon. If you start dockerd with sudo you may want to run docker-compose up with sudo also. otherwise it's fine.

Working solution from https://github.com/docker/compose/issues/4181


When you get an error:

ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?

The solution would be:

  1. First, try verifying Docker Service is Up and Running as expected on your remote/local machine:sudo service docker status

    if Not - run sudo service docker status or sudo systemctl start docker (depends on some linux versions).

  2. Second, start docker as sudo sudo docker-compose up

참고URL : https://stackoverflow.com/questions/29101043/cant-connect-to-docker-from-docker-compose

반응형