3

I want to run a docker container in a Bitbucket pipeline. But I cannot execute any commands as it claims the docker daemon is not running. However, I did not find any way to start it.

INFO     Running command 'which docker' in '/opt/atlassian/pipelines/agent/build'
INFO     STDOUT b'/usr/bin/docker\n'
INFO     STDERR b''
INFO     Running command 'docker --version' in '/opt/atlassian/pipelines/agent/build'
INFO     STDOUT b'Docker version 19.03.15, build 99e3ed8\n'
INFO     STDERR b''
INFO     Running command 'systemctl start docker' in '/opt/atlassian/pipelines/agent/build'
INFO     STDOUT b''
INFO     STDERR b'/bin/sh: 1: systemctl: not found\n'
INFO     Running command 'sudo systemctl start docker' in '/opt/atlassian/pipelines/agent/build'
INFO     STDOUT b''
INFO     STDERR b'/bin/sh: 1: sudo: not found\n'
INFO     Trying to remove old Docker container...
INFO     Running command 'docker container rm test_container' in '/opt/atlassian/pipelines/agent/build'
INFO     STDOUT b''
INFO     STDERR b'Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?\n'

I have read that it is common to pipe the outer daemon into the container somehow but I could not find any way how to achieve this.

So can anyone tell me how this is supposed to work?

I am executing the commands within a python process with "subprocess.Popen(...)" by the way.

This is the corresponding step in the bitbucket-pipelines.yml:

  - step: &test-docker
      name: Build the docker container and run the tests against it
      script:
      - pip install tox
      - docker info
      - tox -e test-docker
      services:
        - docker
Nayaro
  • 117
  • 1
  • 9

2 Answers2

4

To enable docker in bitbucket's pipeline then just add this to the yml file:

options:
  docker: true

definitions:
  services:
    docker:
      memory: 3072

then reference the service on your X step section:

step:
  name: "X"
  services:
    - docker

This worked for me.

AZZ_B
  • 428
  • 5
  • 15
1

There are two options: One is to use a docker-in-docker container. The other approach would be to build the docker image directly in the bitbucket pipeline, start the container and access the service from within the tests directly with http requests on localhost.

Nayaro
  • 117
  • 1
  • 9