Docs and troubleshooting
See original GitHub issueI’m not sure if this is a bug report or a support request; 48 hours and I haven’t been able to do hello world stuff, create iamge.
I’ve been trying to use this package to do the following, locally on windows at first than on azure/gcloud:
- create image from docker file: ideally without using a docker file… I figure with a package like this you could define all parameters in a object instead, which would allow me to treat my server containers like all other objects which I thought would be pretty cool… I’ve been just trying to get an image created with a dockerfile recently because I’m not sure if the prior is even possible with this (no docs I found say).
- build it
- push it
- mount it
- etc
But I can’t seem to create an image. Errors range from “can’t find docker file” to " unexpected EOF" to completing without error but no image showing up locally.
Worth noting, I’m trying to use kotlin not java… is that my problem? Also, I need this to work regardless of how it’s deployed Jar/War/uncompressed.
Here is the folder structure… docker client/http tests work locally, the following content is in Docker.kt and the svrDB is my dockerfile.
Here is what I got so far, it’s a mess from trial and error. If I was smart I’d just use the gradle docker plugin and move along… but it seems a shame not to do this in code if possible, to treat my docker servers like objects would be fantastic!
package com.app.build.containers
import com.github.dockerjava.api.command.BuildImageResultCallback
import com.github.dockerjava.core.DefaultDockerClientConfig
import com.github.dockerjava.core.DockerClientConfig
import com.github.dockerjava.core.DockerClientImpl
import com.github.dockerjava.httpclient5.ApacheDockerHttpClient
import com.github.dockerjava.transport.DockerHttpClient
import java.io.File
const val projectName: String = "srcBuild"
class DockerApi {
private val config: DockerClientConfig = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("tcp://localhost:2375")
//.withDockerTlsVerify(true)
//.withDockerCertPath("/home/user/.docker")
//.withRegistryUsername("admin")
//.withRegistryPassword("password")
//.withRegistryEmail("gunslingor@gmail.com")
//.withRegistryUrl("https://index.docker.io/v1/")
.build()
val httpClient: DockerHttpClient = ApacheDockerHttpClient.Builder()
.dockerHost(config.dockerHost)
.sslConfig(config.sslConfig)
.build()
val dockerClient = DockerClientImpl.getInstance(config, httpClient)!!
val file = DockerApi::class.java.classLoader.getResourceAsStream("dockerfiles/svrDB")
}
fun main(){
val dockerApi = DockerApi()
val clientDocker = dockerApi.dockerClient
val result = clientDocker.infoCmd().exec()
//val filePath = dockerApi.file
//print(filePath)
clientDocker.createImageCmd("test", dockerApi.file).exec()
clientDocker.listImagesCmd()
/*
clientDocker.buildImageCmd(dockerApi.file)
//.withPull(true)
//.withNoCache(true)
//.withTags(setOf("app_dck_dev_svr_build"))
.exec(BuildImageResultCallback())
.awaitImageId();
*/
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (3 by maintainers)
I have not but I will review it in more detail… I don’t usually like to dig into someone else’s code to understand their package, Packages should be atomic by the time they get to me and well documented with instructions… nothing less efficient than reverse engineering IMHO, faster to just run docker commands at the CLI and build up an API. So the real process to use this package is to download the entire code base correct? If so, do I still need to download your compiled packages too via gradle? Seems silly to do both… where should I put your project and what IDE should I be using? I don’t see the idea folder so assume it shouldn’t be intelliJ… lot to manually string together otherwise.
No worries, I don’t really have enough time to put into it, this is 1/1000 packages I was hoping to use in my next app… I couldn’t even identify the create Image test, no idea about your coding policies are here. Will probably just run docker CLI commands from code unless you see that as problematic.
@winthrop-polk
docker-java
is a low level library that allows calling the Docker API. You need to understand the API to be able to work with it.Docker CLI wraps the API and provides high-level commands on top of it (like
docker run
which is a combination of “create container” + “start container” + “attach to container”).You’re free to find (or create) a library on top of docker-java which will give you
docker.image.build(...)
-like experience. This, however, is out of scope ofdocker-java
.This is a class in the same source set. I would suggest to learn a little bit more about Java, how projects are structured, etc etc. docker-java is a standard Maven project and you should have no issues grasping it once you get enough knowledge of Java and Maven-based Java projects.