skip to Main Content

I want to run Docker Compose inside a Docker container using the official docker/compose container.

My Dockerfile looks like this:

FROM docker/compose:latest
WORKDIR /
COPY ./docker-compose.yml .
COPY ./.env .
CMD [ "docker-compose", "up"]

Running docker build -t my-container . works. But running docker run --privileged my-container fails with:

> 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.

What am I doing wrong? Do I have to specify DOCKER_HOST, and if yes, to what?

3

Answers


  1. I guess the image docker/compose is used to in order to build docker-compose tool not to launch docker inside.
    It’s designed to be used by someone who would edit docker-compose source code.

    However you could use the dind image (docker in docker).

    Login or Signup to reply.
  2. Try installing docker-compose within dind (docker-in-docker), like so:

    FROM docker:20.10-dind
    RUN apk add docker-compose
    WORKDIR /
    COPY ./docker-compose.yml .
    COPY ./.env .
    CMD [ "docker-compose", "up"]
    
    Login or Signup to reply.
  3. Try docker run -v /var/run/docker.sock:/var/run/docker.sock -it container_name

    It will share docker socket.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search