-
-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set the ip of the docker container #81
Comments
It has been added to the create params and therefore the run and create command can handle explicit set ip v4 or v6 on the container. In addition, the container builder has UseIpV4 and V6 respectively to allow for explicit ip address on container via the fluent API.
Hi, I've added support for ipv4 and v6 for both run and create commands. I've also added support for the explicit ip setting on container in the fluent API. Can you checkout the code and have a go to reproduce your specific case? Can you submit that as a unit test as a PR? I've added test but have not the time to setup a proper network as of now to test this. But along the lines of. var cmd = _docker.Run("postgres:9.6-alpine", new ContainerCreateParams
{
PortMappings = new[] {"40001:5432"},
Environment = new[] {"POSTGRES_PASSWORD=mysecretpassword"},
Network = "mynetwork",
Ipv4 = "1.1.1.1"
}, _certificates);
var container = cmd.Data;
var insp = _docker.InspectContainer(container, _certificates);
var ip = insp.Data.NetworkSettings.IPAddress;
Assert.AreEqual("1.1.1.1", ip); The above example will create a new container using network mynetwork and set the static ip of 1.1.1.1. The fluent API would look something like this: using (var nw = Fd.UseNetwork("mynetwork").Build())
{
using (
var container =
Fd.UseContainer()
.WithName("mycontainer")
.UseImage("postgres:9.6-alpine")
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
.ExposePort(5432)
.UseNetwork(nw)
.UseIpV4("1.1.1.1")
.WaitForPort("5432/tcp", 30000 /*30s*/)
.Build()
.Start())
{
var ip = container.GetConfiguration().NetworkSettings.IPAddress;
Assert.AreEqual("1.1.1.1", ip);
}
} Cheers, |
It has been added to the create params and therefore the run and create command can handle explicit set ip v4 or v6 on the container. In addition, the container builder has UseIpV4 and V6 respectively to allow for explicit ip address on container via the fluent API.
Hi Mario, Anyway I created my own network and then I tried to set the ip of the newer container to one in that network via fluent API, but it raises me this exception :
I think this happens because the "--ip" arguments has to be added after the name of the custom network, and I don't know if this is possible with the API... Thank you for the support. |
Thanks @adixia ! Can you checkout and try again? --ip or --ip6 are now emitted after the --network. Cheers, |
Hi Mario , still receiving Thanks |
Hi Mario, Have a nice day. |
neat, thanks I'll update and release tomorrow. |
This solves the issue #81 where --network needs to be emitted when static ip is assigned to the container. It also adds two unit tests to ensure both command and fluent API is working properly.
I'll release the new version 2.6.6 now (it will be available in a few hours - depending on nuget indexing). I've also created two unit test to ensure that it is really working: This is the fluent test. using (var nw = Fd.UseNetwork("unit-test-nw")
.UseSubnet("10.18.0.0/16").Build())
{
using (
var container =
Fd.UseContainer()
.WithName("mycontainer")
.UseImage("postgres:9.6-alpine")
.WithEnvironment("POSTGRES_PASSWORD=mysecretpassword")
.ExposePort(5432)
.UseNetwork(nw)
.UseIpV4("10.18.0.22")
.WaitForPort("5432/tcp", 30000 /*30s*/)
.Build()
.Start())
{
var ip = container.GetConfiguration().NetworkSettings.Networks["unit-test-nw"].IPAddress;
Assert.AreEqual("10.18.0.22", ip);
}
} … and this is the command version of the same test... var created = _docker.NetworkCreate("unit-test-nw", new NetworkCreateParams
{
Subnet = new [] {"10.18.0.0/16"}
}, _certificates);
Assert.IsTrue(created.Success);
id = created.Data[0];
var cmd = _docker.Run("postgres:9.6-alpine", new ContainerCreateParams
{
PortMappings = new[] {"40001:5432"},
Environment = new[] {"POSTGRES_PASSWORD=mysecretpassword"},
Network = "unit-test-nw",
Ipv4 = "10.18.0.22"
}, _certificates);
Assert.IsTrue(cmd.Success);
container = cmd.Data;
var insp = _docker.InspectContainer(container, _certificates);
Assert.IsTrue(insp.Success);
var ip = insp.Data.NetworkSettings.Networks["unit-test-nw"].IPAddress;
Assert.AreEqual("10.18.0.22", ip); Cheers, |
Hello,
I would like to create a docker container from a dockerfile and set its IP, e.g 1.1.1.1, on a custom network called mynetwork, like this:
docker run --net mynetwork --ip '1.1.1.1' -it mycontainer
is it possible with FluentDocker?
Thank you for the support
Alessandro
The text was updated successfully, but these errors were encountered: