-1

What I have: I am creating a Jenkins(BlueOcean Pipeline) for CI/CD. I am using the docker in docker approach to use Jenkins as described in the Jenkins docs tutorail. I have tested the setup, it is working fine. I can build and run docker images in the Jenkins container. Now, I am trying to use docker-compose, but it says docker-compose: not found `

Problem:

Unable to use `docker-compose inside the container(Jenkins).

What I want: I want to able to use `docker-compose inside the container using the dind(docker in docker) approach.

Any help would be very much appreciated.

Hanzla
  • 214
  • 5
  • 15
  • I don't get it from the question, have you installed `docker-compose` or not? It's usually installed separately from Docker. See [this](https://docs.docker.com/compose/install/) – anemyte Jun 03 '21 at 13:31
  • I am using the docker container inside the docker approach. The whole approach can be found in the official Jenkins article link attached to the question. – Hanzla Jun 03 '21 at 13:45
  • And yes `docker-compose` is installed locally but it is not available inside the container. – Hanzla Jun 03 '21 at 13:46
  • Things installed locally do no appear in containers on their own. You can attempt mounting it inside but it's best to install it in container. – anemyte Jun 03 '21 at 14:07

2 Answers2

0

Here is my working solution:

FROM maven:3.6-jdk-8

USER root

RUN apt update -y
RUN apt install -y curl

# Install Docker

RUN curl https://get.docker.com/builds/Linux/x86_64/docker-latest.tgz | tar xvz -C /tmp/ && mv /tmp/docker/docker /usr/bin/docker

# Install Docker Compose

RUN curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/bin/docker-compose

# Here your customizations...
Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
  • So you have added these scripts to install docker-compose at the start of your `dockerCompose` file. Right ? – Hanzla Jun 03 '21 at 13:43
  • Exactly, so each Jenkins build can execute docker and compose inside its own docker image. I use that approach since many time. – Antonio Petricca Jun 03 '21 at 13:45
  • Is this approach good? And also are you using Jenkins inside a docker container like the approach I mentioned in the article in my question ? – Hanzla Jun 03 '21 at 13:50
  • Moreover, I am able to use `docker` inside the container to build docker images. But the issue is only with `docker-compose`. So by your approach, I will have to only add docker compose script. – Hanzla Jun 03 '21 at 13:51
  • I have a docker instance build upon a its official docker image. Each Jenkins pipeline generate its own docker image, and inside that I install docker and docker-compose to serve my custom building logic. – Antonio Petricca Jun 03 '21 at 13:53
  • Okay, I think this approach doesn't work for me. If add these script in my `dockerCompose` file, how will I be able to `compose up` the `dockerCompose` file? – Hanzla Jun 03 '21 at 14:00
0

It seems docker-compose is not installed in that machine.
You can check if docker-compose is installed or not using docker-compose --version.
If it is not installed then you can install it in below way :

  1. Using apt- package manager : sudo apt install -y docker-compose
    OR
  2. Using python install manager : sudo pip install docker-compose
Altaf
  • 2,838
  • 1
  • 16
  • 8