how to execute docker commands through Java program

后端 未结 3 1738
礼貌的吻别
礼貌的吻别 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);
    }
    
    0 讨论(0)
  • 2021-01-18 12:23

    To overcome the error you're facing, you should use "-i" instead of "-it". The -t arg tells docker to allocate a pseudo tty.

    Having said that, I agree with Florian, you should use the docker remote api. https://docs.docker.com/engine/reference/api/docker_remote_api/

    0 讨论(0)
  • 2021-01-18 12:39

    I will suggest you, don't use any input or output stream, instead, write the output in a file in the docker image. And read your file in your java main Program.

    Hope this helps

    0 讨论(0)
提交回复
热议问题