部署docker
10分钟学会Docker的安装和使用_docker安装-CSDN博客文章浏览阅读2.5w次,点赞44次,收藏279次。文章目录Docker简介Docker安装Windows安装Linux安装CentOS安装Ubuntu安装最近花了些时间学习docker技术相关,在此做一些总结,供往后复查和像了解docker的学习。Docker简介简而言之,Docker 是一个可供开发者通过容器(container)来构建,运行和共享应用(application)的平台。用容器来部署应用被称为集装箱化(containerization)。想了解更多信息可到docker官网查看。Docker安装Windows安装开启Hyper_docker安装https://blog.csdn.net/baidu_36511315/article/details/108117826Kubeadm部署k8s集群 && kuboard_docker网络kernel: br-4bb47f9dd94a: port 4(vethe833ba-CSDN博客文章浏览阅读572次。k8s安装_docker网络kernel: br-4bb47f9dd94a: port 4(vethe833ba1) entered blocking stathttps://blog.csdn.net/mengo1234/article/details/133899415
docker 配置harbor仓库连接
docker配置远程启动
前提需要docker开启通信功能,有多种开启方式,我使用的是修改注册服务时的配置文件docker.service:
vim /usr/lib/systemd/system/docker.service
ExecStart 添加远程Api启动命令
-H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
docker-Java 连接docker
官网文档 github地址
<!-- docker -->
<!-- https://mvnrepository.com/artifact/com.github.docker-java/docker-java -->
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java</artifactId>
<version>3.3.6</version>
</dependency>
创建client类
package cn.fnii.common.docker;
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.core.DefaultDockerClientConfig;
import com.github.dockerjava.core.DockerClientBuilder;
import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.transport.DockerHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.time.Duration;
@Component
public class BaseDockerClientProxy {
private DockerClient dockerClient;
@Value("${docker.host}")
private String serverUrl;
@Value("${docker.registry.url}")
private String registryUrl;
@Value("${docker.registry.user}")
private String registryUser;
@Value("${docker.registry.pass}")
private String registryPass;
@Autowired
public void setDockerClient() {
// 这里就是获取dockerClient的方法了
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost(serverUrl)
// .withDockerTlsVerify(true)
// .withDockerCertPath("/home/user/.docker")
.withRegistryUsername(registryUser)
.withRegistryPassword(registryPass)
// .withRegistryEmail(registryMail)
.withRegistryUrl(registryUrl)
.build();
dockerClient = DockerClientBuilder.getInstance(config).build();
}
public DockerClient getDockerClient() {
return dockerClient;
}
}
yml配置
docker:
host: tcp://172.171.16.232:2375
registry:
url: harbor.nl.com
user: admin
pass: XXXX
测试docker的查询和上传镜像
测试类
@Slf4j
@SpringBootTest
@ActiveProfiles("dev")
public class DockerTest {
@Autowired
private BaseDockerClientProxy baseDockerClientProxy;
@Test
public void test1() {
List<Image> exec = baseDockerClientProxy.getDockerClient().listImagesCmd().exec();
for (int i = 0; i < exec.size(); i++) {
System.out.println(exec.get(i).getRepoTags());
}
}
@Test
public void test2() {
PushImageResultCallback exec = baseDockerClientProxy.getDockerClient().pushImageCmd("harbor.nl.com/demo/test:1").exec(new PushImageResultCallback());
exec.awaitSuccess();
exec.toString();
}
}