Access services from docker container

jehof February 15, 2018

I am trying to connect to an service (rabbitmq) from a container that I manually run in my bitbucket pipeline. But with no luck. Is this even possible?

Problem is that I have no glue what address/ip/name I could provide to my container for the service. The rabbitmq service starts fine and would be accessible under localhost:5672, but not from within my container, cause this will run in a diffrent network.

Here´s a small example what my setup looks like

image: microsoft/dotnet:sdk
pipelines:
default:
- step:
caches:
- dotnetcore
script: # Modify the commands below to build your repository.
- docker build -t company/image:tag -f ./company/service/Dockerfile ./company/service
- docker run -d --name mycontainer -p 8000:80 -e ASPNETCORE_ENVIRONMENT=Development -e MESSAGEBUS="$CONNECTIONSTRINGS__APITESTSRABBITMQ" company/image:tag
services:
- docker
- rabbitmq
definitions:
services:
rabbitmq:
image: rabbitmq:3-alpine
options:
docker: true

I have defined an environment variable CONNECTIONSTRINGS__APITESTSRABBITMQ with value rabbitmq://guest:guest@localhost:5672, but this is wrong cause rabbitmq is not accessible under this address from my container.

So is it possible to access a service from my container?

3 answers

3 votes
jehof February 15, 2018

I am not sure if this is the correct way, but using --network="host" in docker run command, makes the rabbitmq is accessible via localhost from within my container

gmtborges
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 2, 2018

I got this error when set --network="host"

docker: Error response from daemon: cannot share the host's network namespace when user namespaces are enabled.

1 vote
Rudy Yazdi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 20, 2019

hey guys I'm running into the same issue, have you found a nice way of resolving it?

manuel-koch
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 26, 2019
1 vote
Mark Shropshire
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 3, 2018

I think became not possible after "September 2018 - Docker in Docker User Namespace Remapping" https://confluence.atlassian.com/bitbucket/infrastructure-changes-in-bitbucket-pipelines-872135046.html.

I was trying to run OWASP Zap Baseline from a docker container against the main Pipelines container and I can't access it. https://github.com/zaproxy/zaproxy/wiki/ZAP-Baseline-Scan

Any ideas on a way to do this sort of thing?

Below is a snippet from my bitbucket-pipelines.yml file

- echo "OWASP ZAP report"

- docker version

- docker run -t owasp/zap2docker-stable zap-baseline.py -t http://127.0.0.1:8080

services:

- docker

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events