com.github.dockerjava.api.model.Ports Java Examples

The following examples show how to use com.github.dockerjava.api.model.Ports. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SyndesisIntegrationRuntimeContainer.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public SyndesisIntegrationRuntimeContainer build() {
    CustomizedIntegrationSource source = new CustomizedIntegrationSource(integrationSource, customizers);
    Project project = getProjectBuilder().build(source);

    SyndesisIntegrationRuntimeContainer container = getContainer(project);

    if (enableLogging) {
        container.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("INTEGRATION_RUNTIME_CONTAINER")));
    }

    if (enableDebug) {
        container.withExposedPorts(SyndesisTestEnvironment.getDebugPort());
        container.withCreateContainerCmdModifier(cmd -> cmd.withPortBindings(new PortBinding(Ports.Binding.bindPort(SyndesisTestEnvironment.getDebugPort()),
                new ExposedPort(SyndesisTestEnvironment.getDebugPort()))));
    }

    container.waitingFor(SyndesisTestEnvironment.getIntegrationRuntime().getReadinessProbe().withStartupTimeout(startupTimeout));

    return container;
}
 
Example #2
Source File: MesosMasterContainer.java    From minimesos with Apache License 2.0 6 votes vote down vote up
@Override
protected CreateContainerCmd dockerCommand() {
    int port = getServicePort();
    ExposedPort exposedPort = ExposedPort.tcp(port);

    Ports portBindings = new Ports();
    if (getCluster().isMapPortsToHost()) {
        portBindings.bind(exposedPort, Ports.Binding.bindPort(port));
    }

    CreateContainerCmd cmd = DockerClientFactory.build().createContainerCmd(getImageName() + ":" + getImageTag())
        .withName(getName())
        .withExposedPorts(new ExposedPort(getServicePort()))
        .withEnv(newEnvironment()
            .withValues(getMesosMasterEnvVars())
            .withValues(getSharedEnvVars())
            .createEnvironment())
        .withPortBindings(portBindings);

    MesosDns mesosDns = getCluster().getMesosDns();
    if (mesosDns != null) {
        cmd.withDns(mesosDns.getIpAddress());
    }

    return cmd;
}
 
Example #3
Source File: DockerClientJavaApi.java    From doclipser with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void defaultRunCommand(String eclipseProjectName, String dockerBuildContext) {
    ExposedPort tcp8080 = ExposedPort.tcp(8080);

    CreateContainerResponse container = dockerClient.createContainerCmd("mariolet/my-tomcat")
       .withCmd("true")
       .withExposedPorts(tcp8080)
       .exec();

    Ports portBindings = new Ports();
    portBindings.bind(tcp8080, Ports.Binding(80));

    dockerClient.startContainerCmd(container.getId())
       .withPortBindings(portBindings)
       .exec();
}
 
Example #4
Source File: ConsulContainer.java    From minimesos with Apache License 2.0 6 votes vote down vote up
@Override
protected CreateContainerCmd dockerCommand() {
    int port = getServicePort();
    ExposedPort exposedPort = ExposedPort.tcp(port);

    Ports portBindings = new Ports();
    if (getCluster().isMapPortsToHost()) {
        portBindings.bind(exposedPort, Ports.Binding.bindPort(port));
    }

    ExposedPort consulHTTPPort = ExposedPort.tcp(ConsulConfig.CONSUL_HTTP_PORT);
    ExposedPort consulDNSPort = ExposedPort.udp(ConsulConfig.CONSUL_DNS_PORT);

    return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag())
            .withName(getName())
            .withCmd("agent", "-server", "-bootstrap", "-client", "0.0.0.0")
            .withExposedPorts(consulHTTPPort, consulDNSPort)
            .withPortBindings(portBindings);
}
 
Example #5
Source File: ContainerState.java    From testcontainers-java with MIT License 6 votes vote down vote up
/**
 * Get the actual mapped port for a given port exposed by the container.
 * Should be used in conjunction with {@link #getHost()}.
 *
 * @param originalPort the original TCP port that is exposed
 * @return the port that the exposed port is mapped to, or null if it is not exposed
 */
default Integer getMappedPort(int originalPort) {
    Preconditions.checkState(this.getContainerId() != null, "Mapped port can only be obtained after the container is started");

    Ports.Binding[] binding = new Ports.Binding[0];
    final InspectContainerResponse containerInfo = this.getContainerInfo();
    if (containerInfo != null) {
        binding = containerInfo.getNetworkSettings().getPorts().getBindings().get(new ExposedPort(originalPort));
    }

    if (binding != null && binding.length > 0 && binding[0] != null) {
        return Integer.valueOf(binding[0].getHostPortSpec());
    } else {
        throw new IllegalArgumentException("Requested port (" + originalPort + ") is not mapped");
    }
}
 
Example #6
Source File: StartContainerCmdIT.java    From docker-java with Apache License 2.0 6 votes vote down vote up
@Test(expected = InternalServerErrorException.class)
public void startContainerWithConflictingPortBindings() throws DockerException {

    ExposedPort tcp22 = ExposedPort.tcp(22);
    ExposedPort tcp23 = ExposedPort.tcp(23);

    Ports portBindings = new Ports();
    portBindings.bind(tcp22, Binding.bindPort(11022));
    portBindings.bind(tcp23, Binding.bindPort(11022));

    CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("true")
            .withExposedPorts(tcp22, tcp23).withHostConfig(newHostConfig()
                    .withPortBindings(portBindings))
            .exec();

    LOG.info("Created container {}", container.toString());

    assertThat(container.getId(), not(is(emptyString())));

    dockerRule.getClient().startContainerCmd(container.getId()).exec();
}
 
Example #7
Source File: SyndesisServerContainer.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public SyndesisServerContainer build() {
    SyndesisServerContainer container;
    if (ObjectHelper.isEmpty(serverJarPath)) {
        container = new SyndesisServerContainer(serverJarPath, getJavaOptionString(), deleteOnExit);
    } else {
        container = new SyndesisServerContainer(imageTag, getJavaOptionString());
    }

    if (enableLogging) {
        container.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("SERVER_CONTAINER")));
    }

    container.withCreateContainerCmdModifier(createContainerCmd -> createContainerCmd.withName("syndesis-server"));

    if (enableDebug) {
        container.withExposedPorts(SERVER_PORT, JOLOKIA_PORT, SyndesisTestEnvironment.getDebugPort());
        container.withCreateContainerCmdModifier(cmd -> cmd.withPortBindings(new PortBinding(Ports.Binding.bindPort(SyndesisTestEnvironment.getDebugPort()), new ExposedPort(SyndesisTestEnvironment.getDebugPort()))));
    } else {
        container.withExposedPorts(SERVER_PORT, JOLOKIA_PORT);
    }

    container.waitingFor(new HttpWaitStrategy().forPort(SERVER_PORT)
                                               .withStartupTimeout(Duration.ofMinutes(3)));

    return container;
}
 
Example #8
Source File: DockerComputerSSHConnector.java    From docker-plugin with MIT License 6 votes vote down vote up
@Override
public void beforeContainerCreated(DockerAPI api, String workdir, CreateContainerCmd cmd) throws IOException, InterruptedException {
    // TODO define a strategy for SSHD process configuration so we support more than openssh's sshd
    final String[] cmdArray = cmd.getCmd();
    if (cmdArray == null || cmdArray.length == 0) {
        if (sshKeyStrategy.getInjectedKey() != null) {
            cmd.withCmd("/usr/sbin/sshd", "-D", "-p", String.valueOf(port),
                    // override sshd_config to force retrieval of InstanceIdentity public for as authentication
                    "-o", "AuthorizedKeysCommand=/root/authorized_key",
                    "-o", "AuthorizedKeysCommandUser=root"
            );
        } else {
            cmd.withCmd("/usr/sbin/sshd", "-D", "-p", String.valueOf(port));
        }
    }
    cmd.withPortSpecs(port+"/tcp");
    final PortBinding sshPortBinding = PortBinding.parse(":" + port);
    final Ports portBindings = cmd.getPortBindings();
    if(portBindings != null) {
        portBindings.add(sshPortBinding);
        cmd.withPortBindings(portBindings);
    } else {
        cmd.withPortBindings(sshPortBinding);
    }
    cmd.withExposedPorts(ExposedPort.parse(port+"/tcp"));
}
 
Example #9
Source File: DockerComputerSSHConnector.java    From docker-plugin with MIT License 6 votes vote down vote up
private static InetSocketAddress getBindingForPort(DockerAPI api, InspectContainerResponse ir, int internalPort) {
    // get exposed port
    ExposedPort sshPort = new ExposedPort(internalPort);
    Integer port = 22;
    final NetworkSettings networkSettings = ir.getNetworkSettings();
    final Ports ports = networkSettings.getPorts();
    final Map<ExposedPort, Ports.Binding[]> bindings = ports.getBindings();
    // Get the binding that goes to the port that we're interested in (e.g: 22)
    final Ports.Binding[] sshBindings = bindings.get(sshPort);
    // Find where it's mapped to
    for (Ports.Binding b : sshBindings) {
        String hps = b.getHostPortSpec();
        port = Integer.valueOf(hps);
    }
    String host = getExternalIP(api, ir, networkSettings, sshBindings);
    return new InetSocketAddress(host, port);
}
 
Example #10
Source File: DockerComputerSSHConnectorTest.java    From docker-plugin with MIT License 6 votes vote down vote up
@Test
public void testPortBinding() throws IOException, InterruptedException {
    DockerComputerSSHConnector connector = new DockerComputerSSHConnector(Mockito.mock(DockerComputerSSHConnector.SSHKeyStrategy.class));
    CreateContainerCmdImpl cmd = new CreateContainerCmdImpl(Mockito.mock(CreateContainerCmd.Exec.class), Mockito.mock(AuthConfig.class), "");
    cmd.withPortBindings(PortBinding.parse("42:42"));

    connector.setPort(22);
    connector.beforeContainerCreated(Mockito.mock(DockerAPI.class), "/workdir", cmd);
    final Ports portBindings = cmd.getPortBindings();
    Assert.assertNotNull(portBindings);
    final Map<ExposedPort, Ports.Binding[]> bindingMap = portBindings.getBindings();
    Assert.assertNotNull(bindingMap);
    Assert.assertEquals(2, bindingMap.size());

    final Ports.Binding[] configuredBindings = bindingMap.get(new ExposedPort(42));
    Assert.assertNotNull(configuredBindings);
    Assert.assertEquals(1, configuredBindings.length);
    Assert.assertEquals("42", configuredBindings[0].getHostPortSpec());

    final Ports.Binding[] sshBindings = bindingMap.get(new ExposedPort(22));
    Assert.assertNotNull(sshBindings);
    Assert.assertEquals(1, sshBindings.length);
    Assert.assertNull(sshBindings[0].getHostPortSpec());

    System.out.println();
}
 
Example #11
Source File: CreateContainerCmd.java    From docker-java with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @deprecated see {@link #getHostConfig()}
 */
@Deprecated
@CheckForNull
@JsonIgnore
default Ports getPortBindings() {
    return getHostConfig().getPortBindings();
}
 
Example #12
Source File: ZooKeeperContainer.java    From minimesos with Apache License 2.0 5 votes vote down vote up
@Override
protected CreateContainerCmd dockerCommand() {
    int port = getServicePort();
    ExposedPort exposedPort = ExposedPort.tcp(port);

    Ports portBindings = new Ports();
    if (getCluster().isMapPortsToHost()) {
        portBindings.bind(exposedPort, Ports.Binding.bindPort(port));
    }

    return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag())
        .withName(getName())
        .withExposedPorts(new ExposedPort(ZooKeeperConfig.DEFAULT_ZOOKEEPER_PORT), new ExposedPort(2888), new ExposedPort(3888))
        .withPortBindings(portBindings);
}
 
Example #13
Source File: CreateContainerCmd.java    From docker-java with Apache License 2.0 5 votes vote down vote up
/**
 * Add one or more {@link PortBinding}s. This corresponds to the <code>--publish</code> (<code>-p</code>) option of the
 * <code>docker run</code> CLI command.
 *
 * @deprecated see {@link #getHostConfig()}
 */
@Deprecated
default CreateContainerCmd withPortBindings(PortBinding... portBindings) {
    Objects.requireNonNull(portBindings, "portBindings was not specified");
    getHostConfig().withPortBindings(new Ports(portBindings));
    return this;
}
 
Example #14
Source File: CreateContainerCmd.java    From docker-java with Apache License 2.0 5 votes vote down vote up
/**
 * Add the port bindings that are contained in the given {@link Ports} object.
 *
 * @deprecated see {@link #getHostConfig()}
 */
@Deprecated
default CreateContainerCmd withPortBindings(Ports portBindings) {
    Objects.requireNonNull(portBindings, "portBindings was not specified");
    getHostConfig().withPortBindings(portBindings);
    return this;
}
 
Example #15
Source File: ContainerState.java    From testcontainers-java with MIT License 5 votes vote down vote up
/**
 * @return the bound port numbers
 */
default List<Integer> getBoundPortNumbers() {
    return getPortBindings().stream()
        .map(PortBinding::parse)
        .map(PortBinding::getBinding)
        .map(Ports.Binding::getHostPortSpec)
        .filter(Objects::nonNull)
        .map(Integer::valueOf)
        .collect(Collectors.toList());
}
 
Example #16
Source File: ContainerState.java    From testcontainers-java with MIT License 5 votes vote down vote up
/**
 * @return the port bindings
 */
default List<String> getPortBindings() {
    List<String> portBindings = new ArrayList<>();
    final Ports hostPortBindings = this.getContainerInfo().getHostConfig().getPortBindings();
    for (Map.Entry<ExposedPort, Ports.Binding[]> binding : hostPortBindings.getBindings().entrySet()) {
        for (Ports.Binding portBinding : binding.getValue()) {
            portBindings.add(String.format("%s:%s", portBinding.toString(), binding.getKey()));
        }
    }
    return portBindings;
}
 
Example #17
Source File: DockerComputerSSHConnector.java    From docker-plugin with MIT License 5 votes vote down vote up
private static String getExternalIP(DockerAPI api, InspectContainerResponse ir, NetworkSettings networkSettings,
                             Ports.Binding[] sshBindings) {
    // If an explicit IP/hostname has been defined, always prefer this one
    String dockerHostname = api.getHostname();
    if (dockerHostname != null && !dockerHostname.trim().isEmpty()) {
        return dockerHostname;
    }
    // for (standalone) swarm, need to get the address of the actual host
    if (api.isSwarm()) {
        for (Ports.Binding b : sshBindings) {
            String ipAddress = b.getHostIp();
            if (ipAddress != null && !"0.0.0.0".equals(ipAddress)) {
                return ipAddress;
            }
        }
    }
    // see https://github.com/joyent/sdc-docker/issues/132
    final String driver = ir.getExecDriver();
    if (driver != null && driver.startsWith("sdc")) {
        // We run on Joyent's Triton
        // see https://docs.joyent.com/public-cloud/instances/docker/how/inspect-containers
        return networkSettings.getIpAddress();
    }
    final URI uri = URI.create(api.getDockerHost().getUri());
    if(uri.getScheme().equals("unix")) {
        // Communicating with unix domain socket. so we assume localhost
        return "0.0.0.0";
    }
    return uri.getHost();
}
 
Example #18
Source File: MarathonContainer.java    From minimesos with Apache License 2.0 5 votes vote down vote up
@Override
protected CreateContainerCmd dockerCommand() {
    ExposedPort exposedPort = ExposedPort.tcp(MARATHON_PORT);
    Ports portBindings = new Ports();
    if (getCluster().isMapPortsToHost()) {
        portBindings.bind(exposedPort, Ports.Binding.bindPort(MARATHON_PORT));
    }
    return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag())
            .withName(getName())
            .withExtraHosts("minimesos-zookeeper:" + this.zooKeeper.getIpAddress())
            .withCmd(CollectionsUtils.splitCmd(config.getCmd()))
            .withExposedPorts(exposedPort)
            .withPortBindings(portBindings);
}
 
Example #19
Source File: BesuNode.java    From ethsigner with Apache License 2.0 5 votes vote down vote up
private int portSpec(final Ports ports, final int exposedPort) {
  final Binding[] tcpPorts = ports.getBindings().get(ExposedPort.tcp(exposedPort));
  assertThat(tcpPorts).isNotEmpty();
  assertThat(tcpPorts.length).isEqualTo(1);

  return Integer.parseInt(tcpPorts[0].getHostPortSpec());
}
 
Example #20
Source File: ResultCallback.java    From Core with MIT License 5 votes vote down vote up
private Integer getPort(InspectContainerResponse info) {
    Map<ExposedPort, Ports.Binding[]> portBindings = info.getNetworkSettings().getPorts().getBindings();

    if (portBindings.keySet().size() > 0 && portBindings.keySet().iterator().next().getPort() != 0) {
        return portBindings.keySet().iterator().next().getPort();
    }

    return null;
}
 
Example #21
Source File: DockerTestUtils.java    From module-ballerina-docker with Apache License 2.0 5 votes vote down vote up
/**
 * Create port mapping from host to docker instance.
 *
 * @param dockerPortBindings Ports needed exposed. Key is docker instance port and value is host port.
 * @return The configuration.
 */
private static HostConfig getPortMappingForHost(List<Integer> dockerPortBindings) {
    List<PortBinding> portBindings = new ArrayList<>();

    for (Integer dockerPortBinding : dockerPortBindings) {
        PortBinding portBinding = new PortBinding(
                Ports.Binding.bindIpAndPort("0.0.0.0", Integer.parseInt(dockerPortBinding.toString())),
                ExposedPort.parse(dockerPortBinding.toString()));
        portBindings.add(portBinding);
    }

    return HostConfig.newHostConfig().withPortBindings(portBindings);
}
 
Example #22
Source File: SyndesisDbContainer.java    From syndesis with Apache License 2.0 5 votes vote down vote up
public SyndesisDbContainer() {
    withDatabaseName("sampledb");
    withUsername("sampledb");
    withPassword("secret");

    withCreateContainerCmdModifier(cmd -> cmd.withName("syndesis-db"));
    withCreateContainerCmdModifier(cmd -> cmd.withPortBindings(new PortBinding(Ports.Binding.bindPort(DB_PORT), new ExposedPort(DB_PORT))));
    withInitScript("syndesis-db-init.sql");

    withNetwork(Network.newNetwork());
    withNetworkAliases("syndesis-db");
}
 
Example #23
Source File: DefaultDockerClient.java    From junit5-docker with Apache License 2.0 5 votes vote down vote up
@Override
public String startContainer(String wantedImage, Map<String, String> environment, PortBinding... portBinding) {
    Ports bindings = createPortBindings(portBinding);
    List<String> environmentStrings = createEnvironmentList(environment);
    String containerId = createContainer(wantedImage, bindings, environmentStrings);
    dockerClient.startContainerCmd(containerId).exec();
    return containerId;
}
 
Example #24
Source File: DefaultDockerClient.java    From junit5-docker with Apache License 2.0 5 votes vote down vote up
private String createContainer(String wantedImage, Ports bindings, List<String> environmentStrings) {
    String imageWithVersion = wantedImage;
    if (!imageWithVersion.contains(":")) {
        imageWithVersion += ":latest";
    }
    this.ensureImageExists(imageWithVersion);
    return dockerClient.createContainerCmd(imageWithVersion)
            .withEnv(environmentStrings)
            .withPortBindings(bindings)
            .exec().getId();
}
 
Example #25
Source File: DefaultDockerClient.java    From junit5-docker with Apache License 2.0 5 votes vote down vote up
private Ports createPortBindings(PortBinding... portBinding) {
    Ports bindings = new Ports();
    for (PortBinding binding : portBinding) {
        ExposedPort inner = tcp(binding.inner);
        bindings.bind(inner, bindPort(binding.exposed));
    }
    return bindings;
}
 
Example #26
Source File: DefaultDockerClientIT.java    From junit5-docker with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("start a container with one port")
public void shouldStartContainerWithOnePort() {
    String containerId = defaultDockerClient.startContainer(WANTED_IMAGE, emptyMap(),
        new PortBinding(8081, 8080));
    InspectContainerResponse startedContainer = dockerClient.inspectContainerCmd(containerId).exec();
    Ports ports = startedContainer.getHostConfig().getPortBindings();
    assertThat(ports).isNotNull();
    Map<ExposedPort, Ports.Binding[]> portBindings = ports.getBindings();
    assertThat(portBindings).hasSize(1)
        .containsKeys(new ExposedPort(8080));
    assertThat(portBindings.get(new ExposedPort(8080))).hasSize(1)
        .extracting(Ports.Binding::getHostPortSpec)
        .contains("8081");
}
 
Example #27
Source File: BesuNode.java    From ethsigner with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
  LOG.info("Starting Besu Docker container: {}", besuContainerId);
  docker.startContainerCmd(besuContainerId).exec();

  LOG.info("Querying for the Docker dynamically allocated RPC port numbers");
  final InspectContainerResponse containerResponse =
      docker.inspectContainerCmd(besuContainerId).exec();
  final Ports ports = containerResponse.getNetworkSettings().getPorts();
  final int httpRpcPort = httpRpcPort(ports);
  final int wsRpcPort = wsRpcPort(ports);
  LOG.info("Http RPC port: {}, Web Socket RPC port: {}", httpRpcPort, wsRpcPort);

  final String httpRpcUrl = url(httpRpcPort);
  LOG.info("Besu Web3j service targeting: {} ", httpRpcUrl);

  final HttpService web3jHttpService = new HttpService(httpRpcUrl);
  this.jsonRpc =
      new JsonRpc2_0Web3j(web3jHttpService, pollingInterval, Async.defaultExecutorService());
  final RawJsonRpcRequestFactory requestFactory = new RawJsonRpcRequestFactory(web3jHttpService);
  final JsonRpc2_0Besu besuJsonRpc = new JsonRpc2_0Besu(web3jHttpService);
  final Eth eth = new Eth(jsonRpc);
  final Besu besu = new Besu(besuJsonRpc);
  final Eea eea = new Eea(requestFactory);
  this.accounts = new Accounts(eth);
  this.publicContracts = new PublicContracts(eth);
  this.privateContracts = new PrivateContracts(besu, eea);
  this.transactions = new Transactions(eth);
  this.ports = new NodePorts(httpRpcPort, wsRpcPort);
}
 
Example #28
Source File: HostConfig.java    From docker-maven-plugin with MIT License 4 votes vote down vote up
public Ports getPortBindings() {
	return portBindings;
}
 
Example #29
Source File: PrivateRegistryRule.java    From docker-java with Apache License 2.0 4 votes vote down vote up
/**
 * Starts a local test registry when it is not already started and returns the auth configuration for it
 * This method is synchronized so that only the first invocation starts the registry
 */
@Override
protected void before() throws Throwable {

    int port = 5050;

    String imageName = "private-registry-image";

    File baseDir = new File(DockerRule.class.getResource("/privateRegistry").getFile());

    String registryImageId = dockerClient.buildImageCmd(baseDir)
            .withNoCache(true)
            .start()
            .awaitImageId();

    InspectImageResponse inspectImageResponse = dockerClient.inspectImageCmd(registryImageId).exec();
    assertThat(inspectImageResponse, not(nullValue()));
    DockerRule.LOG.info("Image Inspect: {}", inspectImageResponse.toString());

    dockerClient.tagImageCmd(registryImageId, imageName, "2")
            .withForce().exec();

    // see https://github.com/docker/distribution/blob/master/docs/deploying.md#native-basic-auth
    CreateContainerResponse testregistry = dockerClient
            .createContainerCmd(imageName + ":2")
            .withHostConfig(newHostConfig()
                    .withPortBindings(new PortBinding(Ports.Binding.bindPort(port), ExposedPort.tcp(5000))))
            .withEnv("REGISTRY_AUTH=htpasswd", "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm",
                    "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd", "REGISTRY_LOG_LEVEL=debug",
                    "REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt", "REGISTRY_HTTP_TLS_KEY=/certs/domain.key")
            .exec();

    containerId = testregistry.getId();
    dockerClient.startContainerCmd(containerId).exec();

    // wait for registry to boot
    Thread.sleep(3000);

    // credentials as configured in /auth/htpasswd
    authConfig = new AuthConfig()
            .withUsername("testuser")
            .withPassword("testpassword")
            .withRegistryAddress("localhost:" + port);
}
 
Example #30
Source File: SwarmCmdIT.java    From docker-java with Apache License 2.0 4 votes vote down vote up
private DockerClient initializeDockerClient(Ports.Binding binding) {
    DefaultDockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
        .withRegistryUrl("https://index.docker.io/v1/")
        .withDockerHost("tcp://" + binding).build();
    return getFactoryType().createDockerClient(config);
}