zhyxTo2.0/doc/docker/README.md

106 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#使用docker构建工程步骤
### 1. 使用harbor作为私有库,需要配置maven,找到setting.xml( `linux可以使用find / -name settings.xml`)加入以下配置
```
<servers>
<server>
<id>192.168.0.188</id>
<username>admin</username>
<password>admin12345</password>
<configuration>
<email>smallchill@163.com</email>
</configuration>
</server>
</servers>
<pluginGroups>
<pluginGroup>io.fabric8</pluginGroup>
</pluginGroups>
```
### 2. docker开启远程访问
如果没有远程访问,会报 `Connect to 192.168.0.188:2375 [/192.168.0.188] failed: Connection refused: connect`
在`/usr/lib/systemd/system/docker.service`,配置远程访问。主要是在[Service]这个部分,加上下面两个参数:
```
cd /usr/lib/systemd/system
vi docker.service
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
```
### 3. 配置http访问
因为docker1.3.2版本开始默认docker registry使用的是https我们设置Harbor默认http方式所以当执行用docker login、pull、push等命令操作非https的docker regsitry的时就会报错。
解决办法:配置`/etc/docker/daemon.json`
```
[root@localhost harbor]# vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://3dse7md.mirror.aliyuncs.com"]
}
```
将其修改为:
```
{
"registry-mirrors": ["https://3dse7md.mirror.aliyuncs.com"],
"insecure-registries":["192.168.0.188"]
}
```
### 4. 在每个需要构建子项目的pom.xml下加入配置,内容可参考如下
```
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<skip>${docker.fabric.skip}</skip>
</configuration>
</plugin>
</plugins>
</build>
```
### 5. 在每个需要构建子项目的根目录下加入Dockerfile,内容可参考如下
```
FROM energyx/alpine-java:openjdk8-openj9_cn_slim
MAINTAINER energyjava@qq.com
RUN mkdir -p /energy/gateway
WORKDIR /energy/gateway
EXPOSE 80
ADD ./target/energy-gateway.jar ./app.jar
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "app.jar"]
CMD ["--spring.profiles.active=test"]
```
### 6. 在工程根目录的docker-compose.yml下加入配置内容可参考如下
```
energy-gateway:
image: "${REGISTER}/energy-gateway:${TAG}"
ports:
- 80:80
networks:
energy_net:
ipv4_address: 192.168.2.1
```
### 7. 一切配置完毕采用fabric插件命令执行构建推送
```
mvn clean package docker:build docker:push
```