{"id":18515478,"url":"https://github.com/adambarreiro/docker-client-project","last_synced_at":"2026-05-05T04:36:49.816Z","repository":{"id":77895202,"uuid":"316645522","full_name":"adambarreiro/docker-client-project","owner":"adambarreiro","description":"A client for Docker API using Java and an example of usage with a UI that shows the results of top command on a container.","archived":false,"fork":false,"pushed_at":"2020-12-02T19:18:59.000Z","size":21316,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-17T03:43:31.357Z","etag":null,"topics":["docker","java","maven","spring-boot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adambarreiro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-28T03:03:37.000Z","updated_at":"2021-02-06T18:30:33.000Z","dependencies_parsed_at":"2023-03-04T09:30:28.769Z","dependency_job_id":null,"html_url":"https://github.com/adambarreiro/docker-client-project","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adambarreiro%2Fdocker-client-project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adambarreiro%2Fdocker-client-project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adambarreiro%2Fdocker-client-project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adambarreiro%2Fdocker-client-project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adambarreiro","download_url":"https://codeload.github.com/adambarreiro/docker-client-project/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254150464,"owners_count":22022960,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","java","maven","spring-boot"],"created_at":"2024-11-06T15:47:55.662Z","updated_at":"2025-11-08T06:04:45.492Z","avatar_url":"https://github.com/adambarreiro.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# docker-client-project\n\nThe project has two Maven modules:\n- **docker-java-client**: Java client to consume the Docker API methods.\n- **docker-stats-app**: Web application that serves container CPU/Memory stats to a simple web UI.\n\nBoth components are using Spring Boot.\n\n## docker-java-client\n\nThis client uses the Apache HTTP client to interact with the Docker socket that usually is located at `/var/run/docker.sock`.\nIt can be [configured as any other Spring Boot application](https://docs.spring.io/spring-boot/docs/2.4.0/reference/html/spring-boot-features.html#boot-features-external-config)\nto override this default path and it allows to configure the version of the API to consume.\nYou can check the available configuration parameters [here](docker-java-client/src/main/resources/application.properties).\n\nThis is an example of usage:\n\n```java\n@Autowired\nDocker docker;\n\n// Pull an image. Gets blocked until completion.\ndocker.images().pull(\"openjdk\", \"14-alpine\");\n\n// Runs a container\nString containerId = docker.containers().create(\"java-instance\", \"openjdk:14-alpine\");\nthis.docker.containers().start(containerId);\n\n// Execute some command\nString execId = this.docker.containers().exec(containerId, \"ls\");\nDockerResponse response = this.docker.execs().startInteractive(execId);\n\n// You can do whatever you want with the DockerResponse object obtained.\n// In this case we started an interactive command so the stream is open and\n// information flows until you close it.\nresponse.getContent(); // \u003c- This is a stream\nresponse.close();\n// The response is autocloseable, but as we use .startInteractive() we may want to consume\n// the info for a long time, for example to show CPU stats.\n\n// Now we can clean up\ndocker.containers().stop(containerId);\ndocker.containers().remove(containerId);\n```\n\nThe API methods available in the client are fully documented in their respective interfaces, so you can have a\nlook [here](docker-java-client/src/main/java/com/adambarreiro/docker/client/api). As the API is huge, only a few\nmethods have been implemented, but adding new ones is fairly easy.\n\n## docker-stats-app\n\nThis Spring Boot application offers a simple UI made with a small component done with a few features from [Vue.js](https://vuejs.org/),\nas it extremely easy to render the displayed information dynamically with that framework.\n\n![result](docs/result.png)\n\nThe information shown is transferred through websockets. The server exposes some endpoints to route the container stats\nto the sockets, using [STOMP protocol](http://stomp.github.io/) and [SockJS](https://github.com/sockjs/sockjs-client) in the UI client.\n\nWebsockets were chosen for this use case because they provide real time updates for the container output, and the result\nis quite nice.\n\nIn the current implementation, only one socket can be handled simultaneously as the pool is limited to 1\nthread. This can be easily changed, though.\n\n## Testing\n\nBoth modules have unit testing and the `docker-stats-app` has also integration tests that **require you to have\nthe Docker engine running**.\n\n## Usage\n\nPlease execute these commands depending on what you would like to do:\n\n- `make build`: Execute the Maven build. This step is required to build the Docker image.\n- `make run`: Runs the JAR with your Java installation. You'll need JDK 11.\n- `make docker-build`: Builds the Docker image with the built JAR.\n- `make docker-run`: Runs the Docker container with the application. It assumes you have Docker listening at `/var/run/docker.sock`.\n- `make test`: Execute the unit/integration tests only.\n- `make coverage-report`: Opens the JaCoCo reports in web browser. Runs a build if the reports are not present.\n- `make bugs`: Checks and opens the SpotBugs report.\n\n## Improvements\n\n- Would be nice to refactor the Docker client to implement a more fluid API (builder pattern), for example:\n```\ndocker.images().pull(\"node\",\"latest\").create().start();\n```\n- Missing some Docker API endpoints (only the required for the docker-stats-app are available).\n- Security on websocket communication.\n- `top` command output handling can be improved, right now the UI is parsing it instead of just printing a structured JSON.\n- Allow more than 1 container to be started.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadambarreiro%2Fdocker-client-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadambarreiro%2Fdocker-client-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadambarreiro%2Fdocker-client-project/lists"}