@Override
public void beforeContainerCreated(DockerAPI api, String workdir, CreateContainerCmd cmd) throws IOException, InterruptedException {
if (cmd.getCmd() == null || cmd.getCmd().length == 0) {
if (sshKeyStrategy.getInjectedKey() != null) {
cmd.withCmd("/usr/sbin/sshd", "-D", "-p", String.valueOf(port),
"-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"));
}