Jocker
Java Docker API Client relying on plain Socket
Install / Use
/learn @ndeloof/JockerREADME
Jocker, a Java client library for Docker API
Jocker is (yet another) Docker Client library to access Docker API.

Primary goals are to "keep it simple stupid" and avoid too many dependencies on third-party libraries
Limited dependencies
Most docker client libraries rely on other libs, typically Rest frameworks like Jersey or a full featured HTTP client like Apache Http Client or Netty.
Jocker was initialy designed in the context of Jenkins Docker plugin development. Third party dependencies are constrained in Jenkins by core dependencies, introducing various classpath issues.
Also, such full-features HTTP client libraries demonstrated to have issues supporting some uncommon HTTP usage in
docker APi, like Hijacked HTTP connection to set a bidirectional stdin/stdout multiplexed stream in interactive mode,
or support for /var/run/docker.sock Unix Domain Socket.
For JSON (un)marshalling we rely on Google Gson as a tiny (standalone), simple and efficient JSON library.
KISS (Keep It Simple Stupid)
API model is generated from the Docker official OpenAPI specification. Some pull-requests have been made to help improve this API spec and ensure we get a clean model generated. For the few corner cases where the generated model doesn't offer a nice API, we maintain some dedicated model classes.
Jocker implement HTTP as plain text over a java.net.Socket. This allows transparent support for Unix Domain Socket
thanks to junixsocket. Also can benefit java Channels for non-blocking
I/Os without much efforts.
We don't claim to offer a full featured HTTP client, just implemented what's required for a Docker API server. HTTP, a plain value protocol, is easy to debug and to implement, with only some limited features required by Docker API. The HTTP client implementation is about ~100 lines of code. Doing so, we have full control on HTTP frames and headers over transport, and typically can implement HTTP connection Hijack without any hack.
License
Licensed under BSD Copyright 2017 Nicolas De Loof, Docker Inc.
tl;dr: You're free to use this code, make any changes you need, have fun with it. Contributions are welcome if you do something you consider useful :P
Future plans
- [ ] implement all APIs
- [ ] a fluent client for those who prefer this programming model
- [ ] a swagger codegen template so we generate a plain json-P parser and don't need Gson (code is generated, not intended to be edited)
- [X] use java.nio Channels and jnr-unixsocket to rely on non-blocking I/O
- [ ] conquer the world
How about Docker command line?
Jocker is desgined as a Docker API client, which for many commands is more-or-less
equivalent with the docker command line verbs and flags, with a significant exception
for docker run.
For demonstration purpose, Jocker do include com.docker.jocker.cli package which is
not intended to be used for anything but experiments and demonstration. Still you can
read this code and understand how to fill the gap between the command line you know and
the actual API calls.
If you want to run Jocker as a "command line" demo, just:
- build the command line archive:
mvn compile assembly:single - create an alias:
alias jocker="java -jar target/jocker-0.1-SNAPSHOT-jar-with-dependencies.jar" - enjoy your new docker CLI :P
➜ jocker run -i --rm --name jocker alpine
echo hello $HOSTNAME
hello jocker
Supported APIs :
Missing something ?
If you miss some API support in following list, please consider contributing. In most cases, this is just a question of implementing few lines of code. API type is already generated from docker's swagger API contract, so you only have to implement the method invocation based on API documentation.
public SomeType apiMethod(String param) {
StringBuilder path = new StringBuilder("/v").append(version).append("/some/api?param=").append(param);
Response r = doGET(path.toString());
return gson.fromJson(r.getBody(), SomeType.class);
}
General purpose
- [x] SystemInfo
Containers
- [x] ContainerList
- [x] ContainerCreate
- [x] ContainerInspect
- [ ] ContainerTop
- [x] ContainerLogs
- [ ] ContainerChanges
- [ ] ContainerExport
- [ ] ContainerStats
- [x] ContainerResize
- [x] ContainerStart
- [x] ContainerStop
- [x] ContainerRestart
- [x] ContainerKill
- [ ] ContainerUpdate
- [x] ContainerRename
- [x] ContainerPause
- [x] ContainerUnpause
- [x] ContainerAttach
- [ ] ContainerAttachWebsocket
- [x] ContainerWait
- [x] ContainerDelete
- [x] ContainerArchiveInfo
- [x] ContainerArchive
- [x] PutContainerArchive
- [x] ContainerPrune
- [x] ContainerAttach
Images
- [ ] ImageList
- [x] ImageBuild
- [ ] BuildPrune
- [x] ImageCreate (aka "pull")
- [x] ImageInspect
- [ ] ImageHistory
- [x] ImagePush
- [ ] ImageTag
- [ ] ImageDelete
- [ ] ImageSearch
- [ ] ImagePrune
- [ ] ImageCommit
- [ ] ImageGet
- [ ] ImageGetAll
- [ ] ImageLoad
Exec
- [x] ContainerExec
- [x] ExecStart
- [ ] ExecResize
- [x] ExecInspect
Networks
- [x] NetworkList
- [x] NetworkInspect
- [x] NetworkDelete
- [x] NetworkCreate
- [x] NetworkConnect
- [x] NetworkDisconnect
- [ ] NetworkPrune
Volumes
- [x] VolumeList
- [x] VolumeCreate
- [x] VolumeInspect
- [x] VolumeDelete
- [ ] VolumePrune
Docker Swarm support
There's no short term plan to implement swarm related APIs (Nodes, Services, Tasks, Secrets, Configs) B
Related Skills
node-connect
345.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
106.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
