Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting DOCKER_HOST in .env file #9210

Closed
jmera opened this issue Feb 26, 2022 · 26 comments · Fixed by #9745 or #9817
Closed

Support setting DOCKER_HOST in .env file #9210

jmera opened this issue Feb 26, 2022 · 26 comments · Fixed by #9745 or #9817

Comments

@jmera
Copy link

jmera commented Feb 26, 2022

Description

With Compose V1 we have the ability to set a project-specific DOCKER_HOST in .env, with V2 this is no longer possible.

Steps to reproduce the issue:

  1. Add an .env file with a custom value for DOCKER_HOST
  2. docker compose commands target the default docker host

Describe the results you received:
docker compose commands target the default docker host

Describe the results you expected:
docker compose commands target the docker host specified in .env

Output of docker compose version:

➜  ~ docker compose version
Docker Compose version v2.2.3

Output of docker info:

➜  ~ docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.7.1)
  compose: Docker Compose (Docker Inc., v2.2.3)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 15
 Server Version: 20.10.12
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.10.76-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 5.804GiB
 Name: docker-desktop
 ID: 6IUW:D7VH:NGSI:3VVB:WPYB:EQ3V:6JCD:IARV:6M6N:VRTI:MXNT:RCJ2
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

Additional environment details:
N/A

@prullmann
Copy link

I can confirm that setting DOCKER_HOST in an .env file does not work anymore with docker compose v2.
Also DOCKER_CONTEXT does not work, but would be equally handy.

Steps to reproduce:

docker-compose.yml:

version: '3'
services:
  echo:
    image: alpine
    command: "echo host: $DOCKER_HOST context: $DOCKER_CONTEXT"

.env:

DOCKER_CONTEXT=blubb
DOCKER_HOST=tcp://127.99.99.99:9999

docker-compose v1 (disable "use compose v2" in docker desktop settings) correctly tries to connect to the non-existent host:

% docker-compose up
[...]
docker.errors.DockerException: Error while fetching server API version: HTTPConnectionPool(host='127.99.99.99', port=9999): Max retries exceeded with url: /version (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x10fb97df0>, 'Connection to 127.99.99.99 timed out. (connect timeout=60)'))
[26355] Failed to execute script docker-compose

docker compose v2 ignores both DOCKER_HOST and DOCKER_CONTEXT and connects to the default host instead. It still outputs the correct variable values however:

% docker compose up     
Attaching to docker-test-echo-1
docker-test-echo-1  | host: tcp://127.99.99.99:9999 context: blubb
docker-test-echo-1 exited with code 0

Only when I set DOCKER_HOST or DOCKER_CONTEXT as environment variables, docker compose fails as it should:

% DOCKER_CONTEXT=bar docker compose up
unable to resolve docker endpoint: context "bar" does not exist
% DOCKER_HOST=tcp://127.99.99.99:9999 docker compose up
Cannot connect to the Docker daemon at tcp://127.99.99.99:9999. Is the docker daemon running?

I used bogus host and context values for demonstration purposes. The same holds true for correct values.

Output of docker compose version:

Docker Compose version v2.2.3

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.7.1)
  compose: Docker Compose (Docker Inc., v2.2.3)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 9
  Running: 7
  Paused: 0
  Stopped: 2
 Images: 33
 Server Version: 20.10.12
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.10.76-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 3
 Total Memory: 3.842GiB
 Name: docker-desktop
 ID: RZ7C:BDKF:4WXG:Z5GB:NAVW:U7TN:BUNJ:7PLB:KHVH:2XMW:PQRK:DIUX
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

@hskingr
Copy link

hskingr commented Apr 5, 2022

I have experienced the same issue as prullmann after following their procedure. The DOCKER_HOST variable does work for me in the .env file though.

Output of docker compose version:

Docker Compose version v2.2.3

Output of docker info:

 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.7.1)
  compose: Docker Compose (Docker Inc., v2.2.3)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 16
 Server Version: 20.10.12
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.10.76-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 1.939GiB
 Name: docker-desktop
 ID: Y3MP:EXFO:AJ4H:JHN3:ERHA:QFDT:JG47:YUDW:WRNQ:RV44:DSJI:FRFY
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false```

@ndeloof
Copy link
Contributor

ndeloof commented Apr 6, 2022

related to #9345

@prullmann
Copy link

prullmann commented May 5, 2022

I have experienced the same issue as prullmann after following their procedure. The DOCKER_HOST variable does work for me in the .env file though.

@hskingr Can you please elaborate what works for you and what not?

@trcoelho
Copy link

trcoelho commented May 6, 2022

Any updates on this?
Have facing same problem.

Had to use compose V1 as a result to read DOCKER_HOST from .env file.

@prullmann
Copy link

Had to use compose V1 as a result to read DOCKER_HOST from .env file.

@trcoelho Does that work well for you?
I noticed in my project that some compose commands like docker-compose exec also don't work with v1.
Exec seems to only use DOCKER_HOST from .env to discover the container, but to connect, it falls back to the current docker context and thus fails with Error: No such container: ....
This sounds very much like #6661.

When I run docker context use ... to set the docker context to match the DOCKER_HOST in the .env file, exec works.
Setting DOCKER_HOST or DOCKER_CONTEXT as an environment variable also makes exec work again.
Adding COMPOSE_INTERACTIVE_NO_CLI=1 to the .env file as suggested in #6661 does not work for me.

However, I struggled to create a small example to reproduce this behaviour.
Does exec work for you with compose v1?

@hskingr
Copy link

hskingr commented May 13, 2022

@prullmann

- DOCKER_HOST
- DOCKER_CONTEXT

Both do not work as environment variables in docker compose v2

They both work when docker compose is set to v1 in the docker desktop preferences with the command docker-compose up

docker-compose version

docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1h  22 Sep 2020

docker compose version

Docker Compose version v2.5.0

docker info

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.8.2)
  compose: Docker Compose (Docker Inc., v2.5.0)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 3
  Running: 0
  Paused: 0
  Stopped: 3
 Images: 25
 Server Version: 20.10.14
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc version: v1.0.3-0-gf46b6ba
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.10.104-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 7.774GiB
 Name: docker-desktop
 ID: WXIK:2PC3:ZMKD:EAVM:BDJZ:3ATQ:MKAG:J34Q:Z42E:OW6Q:CO2M:PBCV
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

@prullmann
Copy link

prullmann commented Jun 4, 2022

A few days ago commit #9512 was merged that could also fix this issue.
It looks like it's already included in Compose v2.6.0 and Docker Desktop 4.90 which was released two days ago.

@trcoelho
Copy link

trcoelho commented Jun 6, 2022

Hi @prullmann .

Have checked and still docker compose V2 does not read DOCKER_HOST environment variable as V1 does.
Have tested on latest Docker Desktop Version:

docker info

Client:
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc., v0.8.2)
compose: Docker Compose (Docker Inc., v2.6.0)
sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
scan: Docker Scan (Docker Inc., v0.17.0)

Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.16
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 212e8b6fa2f44b9c21b2798135fc6fb7c53efc16
runc version: v1.1.1-0-g52de29d
init version: de40ad0
Security Options:
seccomp
Profile: default
cgroupns
Kernel Version: 5.10.104-linuxkit
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.939GiB
Name: docker-desktop
ID: 35KN:CMFC:RTCR:5FGL:BI4P:UUYB:W6QF:J7H4:VCOD:W4TD:RYBJ:43IN
Docker Root Dir: /var/lib/docker
Debug Mode: false
HTTP Proxy: http.docker.internal:3128
HTTPS Proxy: http.docker.internal:3128
No Proxy: hubproxy.docker.internal
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
hubproxy.docker.internal:5000
127.0.0.0/8
Live Restore Enabled: false

docker --version

Docker version 20.10.16, build aa7e414

docker-compose --version

Docker Compose version v2.6.0

Thank you.

@prullmann
Copy link

I can confirm that neither DOCKER_HOST nor DOCKER_CONTEXT are picked up by docker compose v2.
So no change with the latest Compose v2.6.0 / Docker 4.9.0 as hoped.

Steps to reproduce:

Make sure DOCKER_HOST and DOCKER_CONTEXT are not set as environment variables and are not already defined in .env. Also check docker context show returns default.

Plain compose command:
docker compose ps -> local docker environment used as expected
docker-compose ps -> local docker environment used as expected
docker-compose ps (v1, 'use compose v2' unchecked in settings) -> local docker environment used as expected

Setting DOCKER_HOST=ssh://[email protected] in .env:
docker compose ps -> local docker environment used, NOT remote environment as expected ❌
docker-compose ps -> local docker environment used, NOT remote environment as expected ❌
docker-compose ps (v1) -> remote environment used as expected ✅
docker-compose exec service echo hello world (v1) -> Error: No such container: 25aaa1fc...
Setting DOCKER_HOST in a custom .env.remote file and using the option --env-file .env.remote yields the same results.

Defining DOCKER_HOST in command line:
DOCKER_HOST=ssh://[email protected] docker compose ps -> remote environment used as expected
DOCKER_HOST=ssh://[email protected] docker-compose ps -> remote environment used as expected
DOCKER_HOST=ssh://[email protected] docker-compose ps (v1) -> remote environment used as expected
Setting an environment variable via export DOCKER_HOST=ssh://[email protected] yields the same results.

Using --host option:
docker --host ssh://[email protected] compose ps -> remote environment used as expected
docker-compose --host ssh://[email protected] ps -> remote environment as expected
docker-compose --host ssh://[email protected] ps (v1) -> remote environment used as expected

Setting DOCKER_CONTEXT=ssh://[email protected] in .env:
docker compose ps -> local docker environment used, NOT remote environment as expected ❌
docker-compose ps -> local docker environment used, NOT remote environment as expected ❌
docker-compose ps (v1) -> local environment used, because compose v1 does not support contexts
Setting DOCKER_CONTEXT in a custom .env.remote file and using the option --env-file .env.remote yields the same results.

Defining DOCKER_CONTEXT in command line:
DOCKER_CONTEXT=remote docker compose ps -> remote environment used as expected
DOCKER_CONTEXT=remote docker-compose ps -> remote environment used as expected
DOCKER_CONTEXT=remote docker-compose ps (v1) -> local environment used, because compose v1 does not support contexts
Setting an environment variable via export DOCKER_CONTEXT=remote yields the same results.
And setting the current context first using docker context use remote also yields the same results.

Using --context option:
docker --context remote compose ps -> remote environment used as expected
docker-compose --context remote ps -> remote environment used as expected
docker-compose --context remote ps (v1) -> remote environment used although compose v1 does not support contexts 🤔

docker info

Client:
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc., v0.8.2)
compose: Docker Compose (Docker Inc., v2.6.0)
sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
scan: Docker Scan (Docker Inc., v0.17.0)

Server:
Containers: 2
Running: 0
Paused: 0
Stopped: 2
Images: 11
Server Version: 20.10.16
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
Default Runtime: runc
Init Binary: docker-init
containerd version: 212e8b6fa2f44b9c21b2798135fc6fb7c53efc16
runc version: v1.1.1-0-g52de29d
init version: de40ad0
Security Options:
seccomp
Profile: default
cgroupns
Kernel Version: 5.10.104-linuxkit
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.843GiB
Name: docker-desktop
ID: DVRV:IQJ6:MFO6:HCDI:TUGK:WCIN:PBMI:EWCZ:FQSN:44PE:ONRA:IXDE
Docker Root Dir: /var/lib/docker
Debug Mode: false
HTTP Proxy: http.docker.internal:3128
HTTPS Proxy: http.docker.internal:3128
No Proxy: hubproxy.docker.internal
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
hubproxy.docker.internal:5000
127.0.0.0/8
Live Restore Enabled: false

@prullmann
Copy link

It seems #9512 by @ulyssessouza implemented feature request #9345 not by loading the default .env file or using one from the --env-file command line argument.
Instead it's loading an env_file specified in a docker_compose.yml, as described in issue #9521.

@trcoelho
Copy link

Hello @prullmann , as we can confirm that is really happening, do we have any scheduled date as a result to solve that?

Thank you.

@prullmann
Copy link

Hi @trcoelho, I am just a user trying to help getting this fixed.
From the git history, it looks like @ulyssessouza and @glours worked on issue #9521, but I can't see if this fixes also our issue here.
New releases seem to be every few weeks, so we'll see if it's fixed quite soon, I guess.

@requiem240sx
Copy link

Also can confirm that this has burned/caught me off guard a few times. I forgot a few months ago, got a new laptop and its happening again.

I use DOCKER_HOST to remotely manage multiple local compose servers and not have configs on the server. This appears to not be possible unless you toggle (enable compose v2) in the docker desktop settings.

An update would be awesome to get this resolved. I'm wondering if I there would be a different way to change the docker daemon to point to a remote host.

@trcoelho
Copy link

trcoelho commented Jul 4, 2022

Hello, have updated to the latest Docker Desktop version 4.10.0 and this issue was not resolved.

docker info

Client:
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc., v0.8.2)
compose: Docker Compose (Docker Inc., v2.6.1)
extension: Manages Docker extensions (Docker Inc., v0.2.7)
sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
scan: Docker Scan (Docker Inc., v0.17.0)

Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 2
Server Version: 20.10.17
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
runc version: v1.1.2-0-ga916309
init version: de40ad0
Security Options:
seccomp
Profile: default
cgroupns
Kernel Version: 5.10.104-linuxkit
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.939GiB
Name: docker-desktop
ID: NVSC:HJGR:ZFQG:IGI7:NA5N:UKHL:7CMX:46VF:KJ2S:UABI:BQGJ:ONNY
Docker Root Dir: /var/lib/docker
Debug Mode: false
HTTP Proxy: http.docker.internal:3128
HTTPS Proxy: http.docker.internal:3128
No Proxy: hubproxy.docker.internal
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
hubproxy.docker.internal:5000
127.0.0.0/8
Live Restore Enabled: false

docker --version

Docker version 20.10.17, build 100c701

Thank you.

@prullmann
Copy link

prullmann commented Jul 8, 2022

I'm wondering if I there would be a different way to change the docker daemon to point to a remote host.

@requiem240sx There is DOCKER_CONTEXT, but that also doesn't work with compose v2 and is non-existent in v1.

@trcoelho
Copy link

trcoelho commented Aug 3, 2022

Hello, do we have any news regarding this one?

Have updated to the latest docker version:

docker info

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.8.2)
  compose: Docker Compose (Docker Inc., v2.7.0)
  extension: Manages Docker extensions (Docker Inc., v0.2.8)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 1
 Server Version: 20.10.17
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc version: v1.1.2-0-ga916309
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.10.104-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 1.938GiB
 Name: docker-desktop
 ID: U6MR:G7JT:YGHA:L24G:AX74:GPBU:4K3V:FUFX:MW6Y:TRSM:ZLRK:HWSX
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

docker --version

Docker version 20.10.17, build 100c701

docker compose version

Docker Compose version v2.7.0

And it still docker compose V2 does not read DOCKER_HOST .env variable.

@ulyssessouza , has any thoughts?

Thank you.

@ulyssessouza
Copy link
Collaborator

What happened here is that the variable was correctly loaded but not applied into docker APIClient.
So it would work for interpolation but not to drive the client.

A fix is on its way -> #9745

@trcoelho
Copy link

Thanks @ulyssessouza !

@trcoelho
Copy link

trcoelho commented Sep 5, 2022

Hi @ulyssessouza , when this will be available?

Thank you!

@milas
Copy link
Contributor

milas commented Sep 6, 2022

Re-opening because we had to revert #9745 in #9792 because it caused issues with TLS-enabled Docker hosts.

As a result, this is not currently available in the latest release of Docker Compose.

@milas
Copy link
Contributor

milas commented Sep 23, 2022

Upon further review, we’ve decided to not support dynamically setting DOCKER_HOST via .env files in Compose v2 (#9871).

Compose v2 is a Docker CLI plugin, and we want to ensure consistent behavior across all CLI plugins, which means using the "inherited" Docker API connection provided to the plugin, respecting all options, such as the active context.

If you were relying on this functionality, I’d recommend taking a look at projects such as direnv, which can automatically set environment variables such as DOCKER_HOST or DOCKER_CONTEXT based on the current directory.

@trcoelho
Copy link

Well, don't get it because we have that behavior on docker compose V1, which helps a lot when we have to manipulate several environments remotely.

Believe keep using V1 then :).

Thanks for the updates.

@prullmann
Copy link

Upon further review, we’ve decided to not support dynamically setting DOCKER_HOST via .env files in Compose v2 (#9871).

@milas Thanks for clarifying, sounds sensible so far.
But what mechanism should now be used when managing different environments (like staging vs production)?

You say that compose should not define the connection depending on its own configuration (eg .env.staging or docker-compose-staging.yml).
That suggests compose should choose its configuration depending on the connection it gets (eg DOCKER_CONTEXT).
Eg by using an .env file like this:

COMPOSE_FILE=docker-compose.yml:docker-compose.${DOCKER_CONTEXT}.yml

Is that the way to go or are there more clever ways?

@trcoelho
Copy link

Hi @milas , as per docker documentation this environment variable should work on docker compose V2:

https://docs.docker.com/compose/environment-variables/envvars/

Is this correct?

If DOCKER_HOST is unavailable for compose V2, what should be the correct way to deploy in different servers?

Thanks in advance.

@hansaskov
Copy link

I know this was closed a while ago, but i would just like to chime in and say that this feature would have been really appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants