Skip to content

Env variables getting overwritten #140

@bendebury

Description

@bendebury

I've got a compose file that looks like this:

services:
  gateway:
    image: docker/mcp-gateway:local
      #    pull_policy: never
    depends_on:
      dind:
        condition: service_healthy
    environment:
      - DOCKER_HOST=tcp://dind:2375
    command:
      - --servers=duckduckgo,exa
      - --secrets=/run/secrets/mcp_secret
      - --transport=streaming
    secrets:
      - mcp_secret

  # Docker-in-Docker sidecar to provide a Docker API without mounting the host socket
  dind:
    image: docker:27-dind
    privileged: true
    environment:
      - DOCKER_TLS_CERTDIR=
    command: ["--host=tcp://*******:2375", "--host=unix:///var/run/docker.sock"]
    healthcheck:
      test: ["CMD", "docker", "info"]
      interval: 5s
      timeout: 3s
      retries: 10

secrets:
  mcp_secret:
    file: .env

When I run this, I get errors that look like this:

gateway-1  | - Listing MCP tools...onfig   w Enable Watch
gateway-1  |   - Running mcp/exa with [run --rm -i --init --security-opt no-new-privileges --cpus 1 --memory 2Gb --pull never -l docker-mcp=true -l docker-mcp-tool-type=mcp -l docker-mcp-name=exa -l docker-mcp-transport=stdio -e EXA_API_KEY]
gateway-1  |   - Running mcp/duckduckgo with [run --rm -i --init --security-opt no-new-privileges --cpus 1 --memory 2Gb --pull never -l docker-mcp=true -l docker-mcp-tool-type=mcp -l docker-mcp-name=duckduckgo -l docker-mcp-transport=stdio]
gateway-1  | - exa: docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

It seems that the culprit may be in this line: It seems that when cmd.Env is set to c.env, the DOCKER_HOST env variable is dropped. Changing this line to cmd.Env = append(os.Environ(), c.env...) fixes my issue, but I'm not sure if that's a desirable fix. Regardless, it does seem like losing DOCKER_HOST is probably not the intended outcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions