[英]docker-compose ignores DOCKER_HOST
I am attempting to run 3 Docker images, MySQL, Redis and a project of mine on Bash for Windows (WSL).我正在尝试在 Bash for Windows (WSL) 上运行 3 个 Docker 映像、MySQL、Redis 和我的一个项目。
To do that I have to connect to the Docker engine running on Windows, specifically on tcp://locahost:2375
.为此,我必须连接到在 Windows 上运行的 Docker 引擎,特别是在
tcp://locahost:2375
。 I have appended the following line to .bashrc
:我已将以下行附加到
.bashrc
:
export DOCKER_HOST=tcp://127.0.0.1:2375
I can successfully run docker
commands like docker ps
or docker run hello-world
but whenever I cd
into my project directory and run sudo docker-compose up --build
to load the images and spin up the containers I get an error:我可以成功运行诸如
docker ps
或docker run hello-world
类的docker
命令,但是每当我cd
进入我的项目目录并运行sudo docker-compose up --build
以加载图像并启动容器时,我都会收到错误消息:
ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?
错误:无法连接到 http+docker://localunixsocket 上的 Docker 守护进程 - 它正在运行吗?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
如果它位于非标准位置,请使用 DOCKER_HOST 环境变量指定 URL。
I know that if I use the -H
argument I can supply the address but I'd rather find a more permanent solution.我知道如果我使用
-H
参数,我可以提供地址,但我宁愿找到一个更永久的解决方案。 For some reason docker-compose
seems to ignore the DOCKER_HOST
environmental variable and I can't figure out why..出于某种原因,
DOCKER_HOST
docker-compose
似乎忽略了DOCKER_HOST
环境变量,我不知道为什么..
Your problem is sudo
.你的问题是
sudo
。 It's a totally different program than your shell and doesn't transfer the exported environment unless you specifically tell it to.它是一个与您的 shell 完全不同的程序,除非您明确告诉它,否则它不会传输导出的环境。 You can either add the following line in your
/etc/sudoers
(or /etc/sudoers.d/docker
):您可以在
/etc/sudoers
(或/etc/sudoers.d/docker
)中添加以下行:
Defaults env_keep += DOCKER_HOST
Or you can just pass it directly to the command line:或者您可以直接将其传递给命令行:
sudo DOCKER_HOST=$DOCKER_HOST docker-compose up --build
By set DOCKER_HOST
you tell for every run of docker in command line to use http api , instead of default - socket on localhost.通过设置
DOCKER_HOST
您告诉命令行中每次运行DOCKER_HOST
使用http api ,而不是默认 - 本地主机上的套接字。
By default http api is not turned on默认情况下, http api未打开
$ sudo cat /lib/systemd/system/docker.service | grep ExecStart
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
you can add -H tcp://127.0.0.1:2375
for tern on http api on localhost but usually you want to tern on api for remote servers by -H tcp://0.0.0.0:2375
(do it only with proper firewall)您可以添加
-H tcp://127.0.0.1:2375
的燕鸥在HTTP API在本地主机上的API,但通常要鸥由远程服务器-H tcp://0.0.0.0:2375
(仅在适当的做防火墙)
so you need to change in /lib/systemd/system/docker.service
to next line所以你需要将
/lib/systemd/system/docker.service
更改为下一行
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://127.0.0.1:2375 --containerd=/run/containerd/containerd.sock
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.