Search code examples
dockerjenkinsdocker-compose

Run Docker Compose inside Jenkins container


I have installed Docker on my server. Then I run Jenkins container on my server. I want to use Jenkins to deploy some Docker containers using Docker Compose with command docker compose up. The command works when I run it on my host, but does not work when I run from inside Jenkins container.

Error message:

jenkins@10818751582e:/$ docker compose 
docker: 'compose' is not a docker command.
See 'docker --help'

Aside from Docker Compose, Docker is still working fine when I run Docker inside Jenkins container, I was able to build, run and push to registry using Docker command, because I bind the following path to the outside host.

    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - /usr/bin/docker:/usr/bin/docker

Solution

  • I don't want to install docker compose into my Jenkins container because I have already install docker compose into my host machine and having two different compose both using the same Docker (Docker was mount into Jenkins container) can result in errors.

    A work around solution that worked for me is from within Jenkins container, I ssh into the outside host and then execute the docker compose from the host. Example of command:

    ssh <user>@172.17.0.1 'docker compose ...'