Suppress docker networking with docker compose for test execution isolation
How do I suppress docker-compose up mapping to the host IP range (for multiple instances)?
Context: I'm looking to run unit tests in Jenkins where we have a docker engine on the master and each slave.
I want to spin up some containers for a unit-integration test and shut them down after.
I want multiple tests to be able to run the same docker compose file simultaneously, without contention.
docker-compose -f "my-test-docker-compose.yml" -p "ab2de2f38c" up -d -t 100
and for the second execution:
docker-compose -f "my-test-docker-compose.yml" -p "34cd832b7" up -d -t 100
I find the first network binds to 0.0.0.0/< port > which causes conflicts when the second execution happens.
Cannot start service zookeeper: driver failed programming external connectivity on endpoint 34cd832b7_zookeeper_1 (c2b928530cfdc7aee17): Bind for 0.0.0.0:22181 failed: port is already allocated
Have tried adding networking to each service and at the bottom and then created the network with docker network create. No dice, thus far.
Ideally want a solution that doesn't require the docker-compose.yml file to change as this gives testers a burden.
Is there a way to suppress any mapping between the containers and the host's IP range and then get the IP from outside the network using docker ps and docker inspect in conjunction.
The ideal would be:
c, err := docker.New("my-test-docker-compose.yml")
//handle err
c.Up()
//connect to a service..
s, err := service1.New(c.GetSocket("serv:1234"))
//handle connection error
//do testing
c.Down()
Any suggestions would be ideal. It may be the only options are to re-work every docker-compose.yml to remove all external network mappings, which is painful or to spawn a docker within a docker to completely isolate the network. Painful.
Any suggestions how to pretty much specify --network=none so we get no 0.0.0.0/ bindings would be great. I note there is a golang docker library (libcompose) in this area, but sadly it's no longer maintained.
Thank you,
alex
docker testing networking docker-compose isolation
add a comment |
How do I suppress docker-compose up mapping to the host IP range (for multiple instances)?
Context: I'm looking to run unit tests in Jenkins where we have a docker engine on the master and each slave.
I want to spin up some containers for a unit-integration test and shut them down after.
I want multiple tests to be able to run the same docker compose file simultaneously, without contention.
docker-compose -f "my-test-docker-compose.yml" -p "ab2de2f38c" up -d -t 100
and for the second execution:
docker-compose -f "my-test-docker-compose.yml" -p "34cd832b7" up -d -t 100
I find the first network binds to 0.0.0.0/< port > which causes conflicts when the second execution happens.
Cannot start service zookeeper: driver failed programming external connectivity on endpoint 34cd832b7_zookeeper_1 (c2b928530cfdc7aee17): Bind for 0.0.0.0:22181 failed: port is already allocated
Have tried adding networking to each service and at the bottom and then created the network with docker network create. No dice, thus far.
Ideally want a solution that doesn't require the docker-compose.yml file to change as this gives testers a burden.
Is there a way to suppress any mapping between the containers and the host's IP range and then get the IP from outside the network using docker ps and docker inspect in conjunction.
The ideal would be:
c, err := docker.New("my-test-docker-compose.yml")
//handle err
c.Up()
//connect to a service..
s, err := service1.New(c.GetSocket("serv:1234"))
//handle connection error
//do testing
c.Down()
Any suggestions would be ideal. It may be the only options are to re-work every docker-compose.yml to remove all external network mappings, which is painful or to spawn a docker within a docker to completely isolate the network. Painful.
Any suggestions how to pretty much specify --network=none so we get no 0.0.0.0/ bindings would be great. I note there is a golang docker library (libcompose) in this area, but sadly it's no longer maintained.
Thank you,
alex
docker testing networking docker-compose isolation
if the services are only talking to each other during testing you don't really need host mappings, perhaps you could just disable those for the tests?
– Uku Loskit
Nov 14 '18 at 13:01
add a comment |
How do I suppress docker-compose up mapping to the host IP range (for multiple instances)?
Context: I'm looking to run unit tests in Jenkins where we have a docker engine on the master and each slave.
I want to spin up some containers for a unit-integration test and shut them down after.
I want multiple tests to be able to run the same docker compose file simultaneously, without contention.
docker-compose -f "my-test-docker-compose.yml" -p "ab2de2f38c" up -d -t 100
and for the second execution:
docker-compose -f "my-test-docker-compose.yml" -p "34cd832b7" up -d -t 100
I find the first network binds to 0.0.0.0/< port > which causes conflicts when the second execution happens.
Cannot start service zookeeper: driver failed programming external connectivity on endpoint 34cd832b7_zookeeper_1 (c2b928530cfdc7aee17): Bind for 0.0.0.0:22181 failed: port is already allocated
Have tried adding networking to each service and at the bottom and then created the network with docker network create. No dice, thus far.
Ideally want a solution that doesn't require the docker-compose.yml file to change as this gives testers a burden.
Is there a way to suppress any mapping between the containers and the host's IP range and then get the IP from outside the network using docker ps and docker inspect in conjunction.
The ideal would be:
c, err := docker.New("my-test-docker-compose.yml")
//handle err
c.Up()
//connect to a service..
s, err := service1.New(c.GetSocket("serv:1234"))
//handle connection error
//do testing
c.Down()
Any suggestions would be ideal. It may be the only options are to re-work every docker-compose.yml to remove all external network mappings, which is painful or to spawn a docker within a docker to completely isolate the network. Painful.
Any suggestions how to pretty much specify --network=none so we get no 0.0.0.0/ bindings would be great. I note there is a golang docker library (libcompose) in this area, but sadly it's no longer maintained.
Thank you,
alex
docker testing networking docker-compose isolation
How do I suppress docker-compose up mapping to the host IP range (for multiple instances)?
Context: I'm looking to run unit tests in Jenkins where we have a docker engine on the master and each slave.
I want to spin up some containers for a unit-integration test and shut them down after.
I want multiple tests to be able to run the same docker compose file simultaneously, without contention.
docker-compose -f "my-test-docker-compose.yml" -p "ab2de2f38c" up -d -t 100
and for the second execution:
docker-compose -f "my-test-docker-compose.yml" -p "34cd832b7" up -d -t 100
I find the first network binds to 0.0.0.0/< port > which causes conflicts when the second execution happens.
Cannot start service zookeeper: driver failed programming external connectivity on endpoint 34cd832b7_zookeeper_1 (c2b928530cfdc7aee17): Bind for 0.0.0.0:22181 failed: port is already allocated
Have tried adding networking to each service and at the bottom and then created the network with docker network create. No dice, thus far.
Ideally want a solution that doesn't require the docker-compose.yml file to change as this gives testers a burden.
Is there a way to suppress any mapping between the containers and the host's IP range and then get the IP from outside the network using docker ps and docker inspect in conjunction.
The ideal would be:
c, err := docker.New("my-test-docker-compose.yml")
//handle err
c.Up()
//connect to a service..
s, err := service1.New(c.GetSocket("serv:1234"))
//handle connection error
//do testing
c.Down()
Any suggestions would be ideal. It may be the only options are to re-work every docker-compose.yml to remove all external network mappings, which is painful or to spawn a docker within a docker to completely isolate the network. Painful.
Any suggestions how to pretty much specify --network=none so we get no 0.0.0.0/ bindings would be great. I note there is a golang docker library (libcompose) in this area, but sadly it's no longer maintained.
Thank you,
alex
docker testing networking docker-compose isolation
docker testing networking docker-compose isolation
asked Nov 14 '18 at 12:28
AlexAlex
355921
355921
if the services are only talking to each other during testing you don't really need host mappings, perhaps you could just disable those for the tests?
– Uku Loskit
Nov 14 '18 at 13:01
add a comment |
if the services are only talking to each other during testing you don't really need host mappings, perhaps you could just disable those for the tests?
– Uku Loskit
Nov 14 '18 at 13:01
if the services are only talking to each other during testing you don't really need host mappings, perhaps you could just disable those for the tests?
– Uku Loskit
Nov 14 '18 at 13:01
if the services are only talking to each other during testing you don't really need host mappings, perhaps you could just disable those for the tests?
– Uku Loskit
Nov 14 '18 at 13:01
add a comment |
1 Answer
1
active
oldest
votes
Ok I've solved this (credit is actually to a team mate).
The solution is to replace ports with expose in the docker-compose.yml file.
Sounds simple but this has the following result:
Before: (HTML table)
<table border=1>
<tr><th>CONTAINER_ID</th><th>....</th><th>PORTS</th></tr>
<tr><td>75a45ac5ef62</td><td>....</td><td>0.0.0.0:9094->9094/tcp, 0.0.0.0:33919->9092/tcp, 0.0.0.0:33918->9093/tcp, 0.0.0.0:33917->22888/tcp</td></tr>
<tr><td>1920786d77ed</td><td>....</td><td>0.0.0.0:9092->9092/tcp, 0.0.0.0:33909->9093/tcp, 0.0.0.0:33908->9094/tcp</td></tr>
</table>After: (HTML table)
<table border=1>
<tr><th>CONTAINER_ID</th><th>....</th><th>PORTS</th></tr>
<tr><td>75a45ac5ef62</td><td>....</td><td>9092-9094/tcp, 22888/tcp, 32888/tcp, 43888/tcp</td></tr>
<tr><td>1920786d77ed</td><td>....</td><td>2181/tcp, 2888/tcp, 3888/tcp, 22888/tcp, 33888/tcp, 42181/tcp, 43888/tcp</td></tr>
</table>So: "0.0.0.0:9094->9094/tcp" becomes "9094-9094/tcp".
The issue was that 'ports' pushed every registered port to the host machine on IP 0.0.0.0. Expose doesn't do this. This way each container in the network can still see each other and resolve but this isn't published out to the host.
This can now be used with docker ps => docker inspect to get the relevant IP for each host declared in the docker-compose.yml file and allow code to run each test in isolation including tests all calling the same file.
Result.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300267%2fsuppress-docker-networking-with-docker-compose-for-test-execution-isolation%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Ok I've solved this (credit is actually to a team mate).
The solution is to replace ports with expose in the docker-compose.yml file.
Sounds simple but this has the following result:
Before: (HTML table)
<table border=1>
<tr><th>CONTAINER_ID</th><th>....</th><th>PORTS</th></tr>
<tr><td>75a45ac5ef62</td><td>....</td><td>0.0.0.0:9094->9094/tcp, 0.0.0.0:33919->9092/tcp, 0.0.0.0:33918->9093/tcp, 0.0.0.0:33917->22888/tcp</td></tr>
<tr><td>1920786d77ed</td><td>....</td><td>0.0.0.0:9092->9092/tcp, 0.0.0.0:33909->9093/tcp, 0.0.0.0:33908->9094/tcp</td></tr>
</table>After: (HTML table)
<table border=1>
<tr><th>CONTAINER_ID</th><th>....</th><th>PORTS</th></tr>
<tr><td>75a45ac5ef62</td><td>....</td><td>9092-9094/tcp, 22888/tcp, 32888/tcp, 43888/tcp</td></tr>
<tr><td>1920786d77ed</td><td>....</td><td>2181/tcp, 2888/tcp, 3888/tcp, 22888/tcp, 33888/tcp, 42181/tcp, 43888/tcp</td></tr>
</table>So: "0.0.0.0:9094->9094/tcp" becomes "9094-9094/tcp".
The issue was that 'ports' pushed every registered port to the host machine on IP 0.0.0.0. Expose doesn't do this. This way each container in the network can still see each other and resolve but this isn't published out to the host.
This can now be used with docker ps => docker inspect to get the relevant IP for each host declared in the docker-compose.yml file and allow code to run each test in isolation including tests all calling the same file.
Result.
add a comment |
Ok I've solved this (credit is actually to a team mate).
The solution is to replace ports with expose in the docker-compose.yml file.
Sounds simple but this has the following result:
Before: (HTML table)
<table border=1>
<tr><th>CONTAINER_ID</th><th>....</th><th>PORTS</th></tr>
<tr><td>75a45ac5ef62</td><td>....</td><td>0.0.0.0:9094->9094/tcp, 0.0.0.0:33919->9092/tcp, 0.0.0.0:33918->9093/tcp, 0.0.0.0:33917->22888/tcp</td></tr>
<tr><td>1920786d77ed</td><td>....</td><td>0.0.0.0:9092->9092/tcp, 0.0.0.0:33909->9093/tcp, 0.0.0.0:33908->9094/tcp</td></tr>
</table>After: (HTML table)
<table border=1>
<tr><th>CONTAINER_ID</th><th>....</th><th>PORTS</th></tr>
<tr><td>75a45ac5ef62</td><td>....</td><td>9092-9094/tcp, 22888/tcp, 32888/tcp, 43888/tcp</td></tr>
<tr><td>1920786d77ed</td><td>....</td><td>2181/tcp, 2888/tcp, 3888/tcp, 22888/tcp, 33888/tcp, 42181/tcp, 43888/tcp</td></tr>
</table>So: "0.0.0.0:9094->9094/tcp" becomes "9094-9094/tcp".
The issue was that 'ports' pushed every registered port to the host machine on IP 0.0.0.0. Expose doesn't do this. This way each container in the network can still see each other and resolve but this isn't published out to the host.
This can now be used with docker ps => docker inspect to get the relevant IP for each host declared in the docker-compose.yml file and allow code to run each test in isolation including tests all calling the same file.
Result.
add a comment |
Ok I've solved this (credit is actually to a team mate).
The solution is to replace ports with expose in the docker-compose.yml file.
Sounds simple but this has the following result:
Before: (HTML table)
<table border=1>
<tr><th>CONTAINER_ID</th><th>....</th><th>PORTS</th></tr>
<tr><td>75a45ac5ef62</td><td>....</td><td>0.0.0.0:9094->9094/tcp, 0.0.0.0:33919->9092/tcp, 0.0.0.0:33918->9093/tcp, 0.0.0.0:33917->22888/tcp</td></tr>
<tr><td>1920786d77ed</td><td>....</td><td>0.0.0.0:9092->9092/tcp, 0.0.0.0:33909->9093/tcp, 0.0.0.0:33908->9094/tcp</td></tr>
</table>After: (HTML table)
<table border=1>
<tr><th>CONTAINER_ID</th><th>....</th><th>PORTS</th></tr>
<tr><td>75a45ac5ef62</td><td>....</td><td>9092-9094/tcp, 22888/tcp, 32888/tcp, 43888/tcp</td></tr>
<tr><td>1920786d77ed</td><td>....</td><td>2181/tcp, 2888/tcp, 3888/tcp, 22888/tcp, 33888/tcp, 42181/tcp, 43888/tcp</td></tr>
</table>So: "0.0.0.0:9094->9094/tcp" becomes "9094-9094/tcp".
The issue was that 'ports' pushed every registered port to the host machine on IP 0.0.0.0. Expose doesn't do this. This way each container in the network can still see each other and resolve but this isn't published out to the host.
This can now be used with docker ps => docker inspect to get the relevant IP for each host declared in the docker-compose.yml file and allow code to run each test in isolation including tests all calling the same file.
Result.
Ok I've solved this (credit is actually to a team mate).
The solution is to replace ports with expose in the docker-compose.yml file.
Sounds simple but this has the following result:
Before: (HTML table)
<table border=1>
<tr><th>CONTAINER_ID</th><th>....</th><th>PORTS</th></tr>
<tr><td>75a45ac5ef62</td><td>....</td><td>0.0.0.0:9094->9094/tcp, 0.0.0.0:33919->9092/tcp, 0.0.0.0:33918->9093/tcp, 0.0.0.0:33917->22888/tcp</td></tr>
<tr><td>1920786d77ed</td><td>....</td><td>0.0.0.0:9092->9092/tcp, 0.0.0.0:33909->9093/tcp, 0.0.0.0:33908->9094/tcp</td></tr>
</table>After: (HTML table)
<table border=1>
<tr><th>CONTAINER_ID</th><th>....</th><th>PORTS</th></tr>
<tr><td>75a45ac5ef62</td><td>....</td><td>9092-9094/tcp, 22888/tcp, 32888/tcp, 43888/tcp</td></tr>
<tr><td>1920786d77ed</td><td>....</td><td>2181/tcp, 2888/tcp, 3888/tcp, 22888/tcp, 33888/tcp, 42181/tcp, 43888/tcp</td></tr>
</table>So: "0.0.0.0:9094->9094/tcp" becomes "9094-9094/tcp".
The issue was that 'ports' pushed every registered port to the host machine on IP 0.0.0.0. Expose doesn't do this. This way each container in the network can still see each other and resolve but this isn't published out to the host.
This can now be used with docker ps => docker inspect to get the relevant IP for each host declared in the docker-compose.yml file and allow code to run each test in isolation including tests all calling the same file.
Result.
<table border=1>
<tr><th>CONTAINER_ID</th><th>....</th><th>PORTS</th></tr>
<tr><td>75a45ac5ef62</td><td>....</td><td>0.0.0.0:9094->9094/tcp, 0.0.0.0:33919->9092/tcp, 0.0.0.0:33918->9093/tcp, 0.0.0.0:33917->22888/tcp</td></tr>
<tr><td>1920786d77ed</td><td>....</td><td>0.0.0.0:9092->9092/tcp, 0.0.0.0:33909->9093/tcp, 0.0.0.0:33908->9094/tcp</td></tr>
</table> <table border=1>
<tr><th>CONTAINER_ID</th><th>....</th><th>PORTS</th></tr>
<tr><td>75a45ac5ef62</td><td>....</td><td>0.0.0.0:9094->9094/tcp, 0.0.0.0:33919->9092/tcp, 0.0.0.0:33918->9093/tcp, 0.0.0.0:33917->22888/tcp</td></tr>
<tr><td>1920786d77ed</td><td>....</td><td>0.0.0.0:9092->9092/tcp, 0.0.0.0:33909->9093/tcp, 0.0.0.0:33908->9094/tcp</td></tr>
</table> <table border=1>
<tr><th>CONTAINER_ID</th><th>....</th><th>PORTS</th></tr>
<tr><td>75a45ac5ef62</td><td>....</td><td>9092-9094/tcp, 22888/tcp, 32888/tcp, 43888/tcp</td></tr>
<tr><td>1920786d77ed</td><td>....</td><td>2181/tcp, 2888/tcp, 3888/tcp, 22888/tcp, 33888/tcp, 42181/tcp, 43888/tcp</td></tr>
</table> <table border=1>
<tr><th>CONTAINER_ID</th><th>....</th><th>PORTS</th></tr>
<tr><td>75a45ac5ef62</td><td>....</td><td>9092-9094/tcp, 22888/tcp, 32888/tcp, 43888/tcp</td></tr>
<tr><td>1920786d77ed</td><td>....</td><td>2181/tcp, 2888/tcp, 3888/tcp, 22888/tcp, 33888/tcp, 42181/tcp, 43888/tcp</td></tr>
</table>edited Nov 14 '18 at 18:20
answered Nov 14 '18 at 17:56
AlexAlex
355921
355921
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300267%2fsuppress-docker-networking-with-docker-compose-for-test-execution-isolation%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
if the services are only talking to each other during testing you don't really need host mappings, perhaps you could just disable those for the tests?
– Uku Loskit
Nov 14 '18 at 13:01