简体   繁体   中英

Disable IPv6 in Docker container from Java

I need to disable IPv6 when starting a Docker container from Java code. Using the command line, it is as follows:

docker run --sysctl net.ipv6.conf.all.disable_ipv6=1 ...

  • Is it possible to do the same but using Java with Spotify's docker-client ?

  • As alternative solution... would it be possible to do with docker-java ?

I think you should be able to do that with our docker-java-api (see Wiki and the linked blog post for details about it): https://www.github.com/amihaiemil/docker-java-api

In principle, it should be as simple as:

final Docker docker = new LocalDocker(...); //or new RemoteDocker(...);
final Container container = docker.containers().create(/*javax.json.JsonObject config*/);

Of course, you have to study the Docker API documentation in order to see what format the JsonObject should have (it should accept config about IpV 6 as well).

Please follow this -

https://github.com/spotify/docker-client/blob/2966b5cad6568d3c1b23f8891fbecab110834785/src/test/java/com/spotify/docker/client/DefaultDockerClientTest.java

 final NetworkConfig networkConfig =
        NetworkConfig.builder().name(networkName).driver("bridge").checkDuplicate(true).ipam(ipam)
            .internal(false).enableIPv6(false).labels(labels)
            .build();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM