无法运行docker-compose

时间:2018-12-30 00:14:26

标签: docker

在Jhipster上this article之后,我构建了项目。但是,我无法运行docker-compose。因此,我尝试找出问题所在。我不走运地一步步走这篇Docker-Compose文章。

$ sudo service docker status
docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2018-12-27 15:40:22 PST; 2 days ago
Docs: https://docs.docker.com
Main PID: 1960 (dockerd)
Tasks: 20 (limit: 4440)
Memory: 68.2M
CGroup: /system.slice/docker.service
       ├─1960 /usr/bin/dockerd -H fd://
       └─2093 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --s

Dec 27 15:40:10 tk-PC dockerd[1960]: time="2018-12-27T15:40:10.493340278-08:00" level=warning msg="Your kernel does not support swap memory li
Dec 27 15:40:10 tk-PC dockerd[1960]: time="2018-12-27T15:40:10.493612101-08:00" level=warning msg="Your kernel does not support cgroup rt peri
Dec 27 15:40:10 tk-PC dockerd[1960]: time="2018-12-27T15:40:10.493681034-08:00" level=warning msg="Your kernel does not support cgroup rt runt
Dec 27 15:40:10 tk-PC dockerd[1960]: time="2018-12-27T15:40:10.496381656-08:00" level=info msg="Loading containers: start."
Dec 27 15:40:17 tk-PC dockerd[1960]: time="2018-12-27T15:40:17.498415923-08:00" level=info msg="Default bridge (docker0) is assigned with an I
Dec 27 15:40:19 tk-PC dockerd[1960]: time="2018-12-27T15:40:19.646853084-08:00" level=info msg="Loading containers: done."
Dec 27 15:40:22 tk-PC dockerd[1960]: time="2018-12-27T15:40:22.512083092-08:00" level=info msg="Daemon has completed initialization"
Dec 27 15:40:22 tk-PC dockerd[1960]: time="2018-12-27T15:40:22.512266914-08:00" level=info msg="Docker daemon" commit=89658be graphdriver=aufs
Dec 27 15:40:22 tk-PC dockerd[1960]: time="2018-12-27T15:40:22.553322342-08:00" level=info msg="API listen on /var/run/docker.sock"
Dec 27 15:40:22 tk-PC systemd[1]: Started Docker Application Container Engine.

$ sudo ls -la /var/run/docker.sock
srw-rw---- 1 root docker 0 Dec 27 15:39 /var/run/docker.sock

$ sudo usermod -aG docker ${USER}

$ docker-compose -f docker-compose.yml build --build-arg UID=$(id -u)
ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

最后一步的结果与“ docker-compose up -d”相同。根据这篇文章,如果此时仍存在问题,那将是一个权限问题。如何找到许可问题?

1 个答案:

答案 0 :(得分:1)

有多种方法可以解决此问题。首先尝试使用以下命令导出Docker主机的环境变量:

export DOCKER_HOST=/var/run/docker.sock

如果可行,您可以将同一行添加到bashrc配置中以永久保存此导出。

如果它不起作用,您可以尝试修改docker daemon配置。它位于

/etc/docker/daemon.json

您需要像这样将localhost附加到主机:

"hosts": ["old_hosts_not_modified_only_append_new_one", "tcp://localhost:2376"],

并使用以下命令重新启动docker daemon:

service docker restart

希望对您有帮助