Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

access to mongo from docker built via pipeline

jmilkiewicz_1 November 29, 2018

Hey

 

I wanna run my tests against mongo service as defined: https://confluence.atlassian.com/bitbucket/test-with-databases-in-bitbucket-pipelines-856697462.html

The only difference to the example above is  that i do NOT wanna to run my tests directly in a script section via `npm test` but i DO wanna to run `npm test` inside just built docker image (so i have more confident that my software works in its final environment - being docker image, not only in bitbucket pipelines).

The problem is that i can not use  "127.0.0.1" as mongo address as it would not reflect mongo run as a service by bitbucket in my docker container (127.0.0.1 would reflect docker container not bitbucket).

I tried to reference bitbucket docker host, so within a script executed in one of my steps i have:

docker build -t xxx .
#trick to get ip address of docker host on which mongo shall be run
DOCKER_HOST_IP=$(ip route | awk 'NR==1 {print $3}')
docker run -e MONGO_HOST="${DOCKER_HOST_IP}" --rm xxx npm run test

With the above setup i get timeout. I suspect that mongo provided as a service is only listening on localhost interface...

In another approach I tried to run docker with host network binding:

docker run --network="host" ...

but it also does not work:

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

 

Any ideas how to access mongo as service from docker built in one of bitbucket steps ? 

 

1 answer

1 accepted

0 votes
Answer accepted
jmilkiewicz_1 December 3, 2018

I found the problem by myself, the trick to get ip of the host via ip route does not work in bitbucket. For now i simply use  default dockerip being 172.17.0.1

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events