-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Karl "Khazrak" Andersson edited this page Jun 15, 2017
·
2 revisions
Welcome to the JDocker wiki!
Quick Example: Map<String, List> ports = new HashMap<>();
HostPort129 port = HostPort129.builder()
.hostPort("8080")
.hostIp("0.0.0.0")
.build();
List<HostPort> portList = new ArrayList<>();
portList.add(port);
ports.put("8080/tcp", portList);
HostConfig hostConfig = HostConfig129
.builder()
.portBindings(ports)
.build();
ContainerCreationRequest request = ContainerCreationRequest129
.builder()
.name("container-name")
.commands(Arrays.asList("ls","-la"))
.image(new DockerImageName("ubuntu:14.04"))
.exposedPort("8080", new Object())
.hostConfig(hostConfig)
.build();
DockerClient client = new DefaultDockerClient129();
String id = client.createContainer(request);
client.start(id);
or using EasyContainer:
EasyContainer129 easyContainer = new EasyContainer129("ubuntu:14.04");
ContainerCreationRequest request = easyContainer.name("container-name")
.cmd("ls -la")
.addPublishPort("0.0.0.0", 13377, 8080)
.buildRequest();
DockerClient client = new DefaultDockerClient129();
String id = client.createContainer(request);
client.start(id);