Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Use Docker within Bitbucket pipe



I wrote my 1st own Bitbucket Pipe using Python. It's supposed to tag a docker image and push it to a registry. So I have to use Docker within the pipe itself. Everything is working nicely locally. But using my pipe in a Bitbucket pipeline fails because I don't get Docker to work. Here is what I try to do:

def get_client(self):
      if self.docker_client is None:
        self.docker_client = docker.APIClient(base_url='unix://var/run/docker.sock')
      return self.docker_client

The complete code of my pipe can be found in this public repository:

I cannot find any documentation on how to connect to Docker from within a Bitbucket Pipe. Does anybody have experience with that?

Thanks and cheers,



1 answer

The docker daemon is not needed within the pipe container, just the docker client.

When the pipe is started, the docker socket will be mounted into the pipe container, the docker client then can do it's job. 

Thanks. But how do I call the client? from_env() does not seem to work for me.

@christoph were you able to install the binary of the docker client? the "docker" command should then be available in the container. e.g. "docker --version" should give some output.

Yes @ktomk. A "docker --version" run inside the container leads to the following output "INFO: docker --version = 3.7.0".

But the command "docker_client = docker.from_env()" fails.

I also tried "docker_client = docker.APIClient(base_url='unix://var/run/docker.sock')" since I need the low-level APi. But this does not seem to work.

I assume you use some software runtime here (python?) and that is about specific libraries in there. I'm not a strong practitioner at python, most likely the normally fine command "docker.from_env()" does not work out of the box within the pipeline / pipe environment? (at least for you, no pun intended)

This can lead to a lot of guess work. It might be more straight forward to check the specification of the lib and if the example container image you mentioned earlier is similar, to review the sources of it what might be different and more importantly what makes the difference. Depending on your way of work the first or the second works better for you.

As (let's say) it's python, fast feedback cycles might be possible by having a build script to build the pipe container and then call it with the parameters on your local system by executing the docker command. When you setup a pipeline in a bitbucket repository and run it, bitbucket shows how the pipe is executed. this can be easily mocked locally with much faster iteration.

Keeping the pipe container running after fail does also allow to inspect it. Something that is not feasible within a pipeline run on bitbucket cloud.

I hope that helps a bit. I do see in the repo you linked that it's the same command in python, so don't want to sound ignorant here. just saying.

Hi Christoph,

Have you been successful in making ```docker_client = docker.from_env()``` work in a bitbucket pipeline?

I'm running into the same problem...


Hi Benoit,

no... I have not. I am now using Kaniko within the pipeline to get the job done.



Like ktomk likes this

Thanks for the reply! Actually I realized the docker service was in other steps but not in this one (my bad).

When adding it, with something like:

   - step:
         - pip install poetry==1.1.4
         - poetry install -vv
         - poetry run pytest -v --tb=line

         - docker
         - docker
         - pip
         - poetry-path
         - poetry-venv


then docker_client=docker.from_env()  worked for me

Like ktomk likes this

Good point... that's a different case.

Like ktomk likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

185 views 2 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you