testcontainers-node icon indicating copy to clipboard operation
testcontainers-node copied to clipboard

Gitlab CI ERROR Failed to up DockerCompose environment: Error: spawn docker-compose ENOENT

Open juanfernandez-gh opened this issue 5 years ago • 4 comments

Hi,

I'm trying to run the container from a docker compose in the pipeline but it fails with above mentioned error, locally it works fine.

I'm using:

[email protected]

docker-compose.yaml:

version: '3.1'

services:
  mongo:
    image: mongo
    restart: always
    ports:
      - 27017

function to up environment:

export const initMongoDBContainer = async () => {
    try {
        const composeFilePath = path.resolve(__dirname, "../../docker");
        environment = await new DockerComposeEnvironment(composeFilePath, "docker-compose.yml").up();
        mongoContainer = environment.getContainer('mongo_1');
        const MAPPED_PORT = mongoContainer.getMappedPort(MONGODB_DEFAULT_PORT);
        process.env.MONGODB_URL = `mongodb://${mongoContainer.getHost()}:${MAPPED_PORT}/db-data`;
        process.env.MONGODB_DEFAULT_PORT = String(MONGODB_DEFAULT_PORT);
        return mongoContainer;
    } catch(e) {
        console.error(`Error initializing mongo container: ${e}`);
    }
};

These are the debug logs from testcontainer on the pipeline:

2021-07-13T15:55:21.421Z testcontainers INFO Starting DockerCompose environment testcontainers-9d8b37aee4655991ffbd87adb66e9fac
2021-07-13T15:55:21.423Z testcontainers DEBUG Creating new DockerClient
2021-07-13T15:55:21.424Z testcontainers INFO Detected DOCKER_HOST environment variable: tcp://docker:2375
2021-07-13T15:55:21.425Z testcontainers INFO Using Docker host from modem: docker
2021-07-13T15:55:21.425Z testcontainers DEBUG Creating new Reaper for session: 73ce89f52fba6a8d481e11be02ac09b4
2021-07-13T15:55:21.443Z testcontainers DEBUG No registry auth locator found for registry: "https://index.docker.io/v1/"
2021-07-13T15:55:21.443Z testcontainers INFO Pulling image: cristianrgreco/ryuk:0.4.0
2021-07-13T15:55:22.630Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 0.4.0 - Pulling from cristianrgreco/ryuk
2021-07-13T15:55:22.632Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 31603596830f - Pulling fs layer
2021-07-13T15:55:22.633Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 8744d96f6c81 - Pulling fs layer
2021-07-13T15:55:22.633Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 62e89d6d1696 - Pulling fs layer
2021-07-13T15:55:23.177Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 62e89d6d1696 - Downloading 1%
2021-07-13T15:55:23.198Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 31603596830f - Downloading 1%
2021-07-13T15:55:23.200Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 8744d96f6c81 - Downloading 1%
2021-07-13T15:55:23.233Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 8744d96f6c81 - Verifying Checksum
2021-07-13T15:55:23.234Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 8744d96f6c81 - Download complete
2021-07-13T15:55:23.243Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 62e89d6d1696 - Verifying Checksum
2021-07-13T15:55:23.243Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 62e89d6d1696 - Download complete
2021-07-13T15:55:23.271Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 31603596830f - Verifying Checksum
2021-07-13T15:55:23.271Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 31603596830f - Download complete
2021-07-13T15:55:23.290Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 31603596830f - Extracting
2021-07-13T15:55:23.480Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 31603596830f - Pull complete
2021-07-13T15:55:23.485Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 8744d96f6c81 - Extracting
2021-07-13T15:55:23.629Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 8744d96f6c81 - Pull complete
2021-07-13T15:55:23.636Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 62e89d6d1696 - Extracting
2021-07-13T15:55:23.782Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - 62e89d6d1696 - Pull complete
2021-07-13T15:55:23.796Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - Digest: sha256:e1f13eca329e43f03f38786406507c65162e63acd35e7d4c3708b25a6c80f791
2021-07-13T15:55:23.801Z testcontainers TRACE Pulling cristianrgreco/ryuk:0.4.0 - Status: Downloaded newer image for cristianrgreco/ryuk:0.4.0
2021-07-13T15:55:23.808Z testcontainers INFO Creating container for image: cristianrgreco/ryuk:0.4.0
2021-07-13T15:55:24.401Z testcontainers INFO Starting container cristianrgreco/ryuk:0.4.0 with ID: 8489e965ae1d9e2c70e9e570710d2b3a6ffdf1c9f11ced42568235b8d2d67c26
2021-07-13T15:55:24.661Z testcontainers DEBUG Waiting for container to be ready: 8489e965ae1d9e2c70e9e570710d2b3a6ffdf1c9f11ced42568235b8d2d67c26
2021-07-13T15:55:24.662Z testcontainers DEBUG Waiting for log message "Started!"
2021-07-13T15:55:24.666Z testcontainers INFO Container is ready
2021-07-13T15:55:24.666Z testcontainers DEBUG Connecting to Reaper on docker:18118
2021-07-13T15:55:24.668Z testcontainers DEBUG Connected to Reaper
2021-07-13T15:55:24.671Z testcontainers INFO Upping DockerCompose environment
2021-07-13T15:55:24.679Z testcontainers ERROR Failed to up DockerCompose environment: Error: spawn docker-compose ENOENT
2021-07-13T15:55:24.680Z testcontainers INFO Downing DockerCompose environment
2021-07-13T15:55:24.687Z testcontainers ERROR Failed to down DockerCompose environment: undefined
2021-07-13T15:55:24.688Z testcontainers WARN Failed to stop DockerCompose environment after failed up

juanfernandez-gh avatar Jul 13 '21 16:07 juanfernandez-gh

hi @juanf9224, seems to me that the docker-compose binary isn't installed on the machine

cristianrgreco avatar Jul 13 '21 16:07 cristianrgreco

@juanf9224 From this StackOverflow it seems trivial to install docker-compose as part of the build: https://stackoverflow.com/questions/39868369/run-docker-compose-build-in-gitlab-ci-yml

# .gitlab-ci.yml
image: docker
services:
  - docker:dind    
build:
  script:
    - apk add --no-cache docker-compose
    - docker-compose up -d

Does this work for you?

cristianrgreco avatar Jul 13 '21 16:07 cristianrgreco

FYI if you upgrade to testcontainers 7.13.0 you should see a WARN log saying that docker-compose isn't installed

cristianrgreco avatar Jul 13 '21 16:07 cristianrgreco

Thanks for your answer @cristianrgreco , I went back to using the generic containers instead, since I only need it for simple testing purposes and don't want to add more to the pipeline.

juanfernandez-gh avatar Jul 13 '21 17:07 juanfernandez-gh