Docker-Client(Java)通过Dockerfile创建镜像

  1. 引入docker-java依赖

    
            com.github.docker-java
            docker-java
            3.0.14
    
    
  2. 与目标服务器建立连接

    
    DockerClient dockerClient = 
    DockerClientBuilder.getInstance("tcp://xxx.xxx.xxx.xxx:2375").build();
    
    
  3. 创建镜像

    File baseDir = new File("~/kpelykh/docker/netcat");
    BuildImageResultCallback callback = new BuildImageResultCallback() {
    	@Override
    	public void onNext(BuildResponseItem item) {
      			System.out.println("" + item);
      			super.onNext(item);
    	}
    };
    dockerClient.buildImageCmd(baseDir).exec(callback).awaitImageId();
    
    

你可能感兴趣的:(Linux)