3

I face this error when try to run bitbucket pipelines with test container

Could not start container java.lang.IllegalStateException: Container did not start correctly.

There is no another issues but maybe it's related to Binds? Logs:

"HostConfig":"Binds":["/opt/atlassian/pipelines/agent/build/src/test/resources:/opt/atlassian/pipelines/agent/build/src/test/resources:rw","/var/run/docker.sock:/docker.sock:rw"]

Pipelines config:

pipelines:
  pull-requests:
    '**':
       - step:
           name: Integration tests
           caches:
              - maven
           after-script:
              - pipe: atlassian/checkstyle-report:0.3.0
           script:
              - export TESTCONTAINERS_RYUK_DISABLED=true
              - export TESTCONTAINERS_CHECKS_DISABLE=true
              - mvn -B verify -Dsurefire.skip=true --file pom.xml
           services:
              - docker
       - step:
           name: Build
           caches:
              - maven
           after-script:
              - pipe: atlassian/checkstyle-report:0.3.0
           script:
              - mvn -B package --file pom.xml -DskipTests
           services:
              - docker
definitions:
   services:
      docker:
         memory: 3072

docker-compose.yml

services:
  db:
    image: postgres:14.1
    ports:
       - "5432:5432"
    expose:
       - "5432"
    networks:
       - example-network
    environment:
       - "POSTGRES_USER=${DB_USER:-postgres}"
       - "POSTGRES_PASSWORD=${DB_PASSWORD:-postgres}"
       - "POSTGRES_DB=${DB_SCHEMA:-testdb}"
    logging:
       driver: json-file
       options:
          mode: "non-blocking"
 networks:
    example-network:
       driver: bridge

docker compose container:

    DOCKER_COMPOSE_CONTAINER =
        new DockerComposeContainer(new File("src/test/resources/docker-compose.yml"))
                .withExposedService(SERVICE_NAME, SERVICE_PORT, 
    Wait.forListeningPort());
    DOCKER_COMPOSE_CONTAINER.start();

I also tried without TESTCONTAINERS_CHECKS_DISABLE=true but there was error like

Status 403: {"message":"authorization denied by plugin pipelines: -v only supports $BITBUCKET_CLONE_DIR and its subdirectories"}

Could anyone help with this please?

puka
  • 83
  • 3
  • Would you please fix the indentation of both your bitbucket-pipelines.yml and your docker-compose.yml? They are both invalid! Indentation of that java snippet is also misleading. – N1ngu Jun 04 '22 at 17:46

1 Answers1

1

As the error message you got explains, Bitbucket Pipelines Docker engine only lets mounting subdirectories of your project sources.

I don't know why you intend to mount /var/run/docker.sock or if you can avoid it, but the way Bitbucket usually forwards the Docker engine to spawned containers, e.g. in pipes, is by setting

...
--env=DOCKER_HOST="tcp://host.docker.internal:2375" \
--add-host="host.docker.internal:$BITBUCKET_DOCKER_HOST_INTERNAL" \
...

so might need to imitate that.

N1ngu
  • 2,862
  • 17
  • 35
  • Thanks for your answer. But I don't intend to mount /var/run/docker.sock. Just saw it in the logs. I did not add any other settings besides the presented files. I saw these two lines in the logs as well. 'docker container run ... --env=DOCKER_HOST="tcp://host.docker.internal:2375" \ --add-host="host.docker.internal:$BITBUCKET_DOCKER_HOST_INTERNAL" \ ...' Maybe I have to add some additional properties? – puka Jun 05 '22 at 16:15
  • Even if the docker host is being correctly configured, I fear you might be still unintentionally mounting the /var/run/docker.sock volume. – N1ngu Jun 08 '22 at 07:18