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: https://bitbucket.org/humanitec/push-to-humanitec/src/master/
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,
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.
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:
- pip install poetry==1.1.4
- poetry install -vv
- poetry run pytest -v --tb=line
then docker_client=docker.from_env() worked for me
...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...
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