Elias Schoof
Elias Schoof

Reputation: 2046

Docker: How to use "docker/compose" container?

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?

Upvotes: 0

Views: 888

Answers (3)

Escobar
Escobar

Reputation: 209

Try docker run -v /var/run/docker.sock:/var/run/docker.sock -it container_name

It will share docker socket.

Upvotes: 0

Ron van der Heijden
Ron van der Heijden

Reputation: 15070

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"]

Upvotes: 0

SCcagg5
SCcagg5

Reputation: 647

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

Upvotes: 2

Related Questions