Java access to Docker environments

Source: Internet
Author: User

1. Configuring the Environment

New Execstart=/usr/bin/dockerd-h tcp://0.0.0.0:2375-h Unix://var/run/docker.sock

[Email protected]:~# nano/lib/systemd/system/docker.service
[Email protected]:~# cat/lib/systemd/system/docker.service
[Unit]
Description=docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target Docker.socket Firewalld.service
Wants=network-online.target
Requires=docker.socket

[Service]
Type=notify
# The default is not-use SYSTEMD for cgroups because the delegate issues still
# exists and SYSTEMD currently does not support the Cgroup feature set required
# for containers run by Docker
Execstart=/usr/bin/dockerd-h tcp://0.0.0.0:2375-h Unix://var/run/docker.sock
Execreload=/bin/kill-s HUP $MAINPID
limitnofile=1048576
# have Non-zero limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
Limitnproc=infinity
Limitcore=infinity
# uncomment Tasksmax If your SYSTEMD version supports it.
# only SYSTEMD 226 and above support this version.
Tasksmax=infinity
Timeoutstartsec=0
# Set delegate yes so, SYSTEMD does not reset the cgroups of Docker containers
Delegate=yes
# kill only the Docker process, not all processes in the Cgroup
Killmode=process
# Restart the Docker process if it exits prematurely
Restart=on-failure
Startlimitburst=3
startlimitinterval=60s

[Install]
Wantedby=multi-user.target
Restart Docker

[Email protected]:~# service Docker Reload
Warning:docker.service changed on disk. Run ' Systemctl daemon-reload ' to reload units.
[Email protected]:~# systemctl daemon-reload
[Email protected]:~# systemctl Docker restart
Unknown Operation Docker.
[Email protected]:~# service Docker restart
Detecting the configured ports

[Email protected]:~# netstat-antp | grep 2375
TCP6 0 0::: 2375:::* LISTEN 19143/dockerd

2. Java Access client

Loading the Docker-java jar

<!--Https://mvnrepository.com/artifact/com.github.docker-java/docker-java--
<dependency>
<groupid>com.github.docker-java</groupId>
<artifactid>docker-java</artifactId>
<version>3.0.14</version>
</dependency>


Initializing Client Access
Dockerclient dockerclient = dockerclientbuilder.getinstance (). build ();

Java access to Docker environments

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.