how to execute docker commands through Java program

后端 未结 3 1783
礼貌的吻别
礼貌的吻别 2021-01-18 11:44

Instead of calling Docker remote APIs, I need develop a program which just talks to Docker Linux Client (not Docker daemon). Here is my code

    try {
               


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-18 12:21

    You can use docker client for java (e.g. https://github.com/spotify/docker-client). Here is example of usage:

    public void startContainer(String containerId) throws Exception {
        final DockerClient docker = DefaultDockerClient.builder()
                .uri(URI.create("https://192.168.64.3:2376"))
                .dockerCertificates(new DockerCertificates(Paths.get("/Users/d.romashov/.docker/machine/machines/dinghy")))
                .build();
    
        docker.startContainer(containerId);
    }
    

提交回复
热议问题