How to run on self-hosted docker in --network host mode for bitbucket pipeline

Nikhil Chowdary Gutlapalli December 11, 2024

I have a self-hosted docker which runs on bitbucket pipeline. I wanted to make sure that this docker container should runs in network host mode. 

Where do I need to specify to make sure the pipeline container opens in that network mode?

1 answer

0 votes
Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 15, 2024

G'day, @Nikhil Chowdary Gutlapalli 

Welcome to the community!

May I know by self-hosted do you mean our Bitbucket runner? If yes, I believe the following KB should be able to help you achieve in using --network in your pipeline build:

Using --network parameter in Docker commands in Bitbucket Pipelines

Regards,
Syahrul

Nikhil Chowdary Gutlapalli December 16, 2024

Hi @Syahrul 

Thanks for your response. Yes, I mean Bitbucket runner.

The following KB link you provided is redirecting to this same page. Can you please check the link again?

Best,

Nikhil

Nikhil Chowdary Gutlapalli December 16, 2024

Wanted to provide more info.

I have created an image using DockerFile and I pushed the image to the DockerHub.

And in my bitbucket-pipeline.yml, I am calling that docker image.

This is the basic code:


image
: gcc:10.2
pipelines:
      default:
            - step:
                  name: Build
                  script:
                        - ifconfig
                  image: localhost:5000/docker_test:2023.2
                  runs-on:
                                    - 'self.hosted'
                                    - 'linux'

The ifconfig prints the docker network ports. I wanted to get all the host machine ports, which can be achieved if I run the docker container manually on my host with --newtork host command.
As this pipeline is creating the container from the image and closing it at the end, I wasn't sure where to provide this flag. Tried to provide it on runner command, but it didn't make a change.
Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 16, 2024

Hey @Nikhil Chowdary Gutlapalli 

I apologize for the invalid link, please check the following link:

Using --network parameter in docker 

That said, the runner's container starts with the --network host option. However, during the build process, the build container is launched as a sidecar with bridge networking, instead of host networking. This configuration is part of the internal networking setup to facilitate communication between containers associated with the runners.

To ensure proper network functionality, please follow these steps:

  1. Enable IP Forwarding: Run the following command on the runner's host machine to check if IP forwarding is enabled:
    sysctl net.ipv4.ip_forward
  2. Verify NAT Rules: Use iptables to ensure that traffic from the Docker bridge network is correctly routed through the host network:
    iptables -t nat -L -n -v

Regards,
Syahrul

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events