1、服务器 -- 安装 docker
参考 https://blog.csdn.net/sky_eyeland/article/details/101200959
2、服务器 -- 安装 docker-registry
- docker-compose.yml
version: "3"
services:
registry:
image: docker.io/registry
ports:
- "5000:5000"
volumes:
- "/usr/local/work/docker/registry:/var/lib/registry"
container_name: registry
privileged: true
- 开启 tcp 2375 端口
# 编辑文件
vim /lib/systemd/system/docker.service
# 修改内容,改为
ExecStart=/usr/bin/dockerd-current -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock \
- 重启 docker
systemctl daemon-reload && systemctl restart docker
- 重启 docker-registry
docker start 2e
3、查看启动状态
systemctl status docker
docker ps -a
lsof -i:2375
4、maven 项目配置 -- jar 方式
- 创建目录
# 创建目录
src/main/docker
# 添加 Dockfile 文件
FROM daocloud.io/library/java:openjdk-8u40-jdk
MAINTAINER vim
VOLUME /tmp
ARG JAR_FILE
ADD ${JAR_FILE} app.jar
ENV JAVA_OPTS=""
ENTRYPOINT ["sh","-c","java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar"]
- maven 配置
<properties>
<docker.registry>192.168.147.130:5000</docker.registry>
</properties>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<!-- <execution>
<id>push-image</id>
<phase>package</phase>
<goals>
<goal>push</goal>
</goals>
</execution>-->
</executions>
<configuration>
<imageName>${docker.registry}/${project.name}:${project.version}</imageName>
<imageTags>
<imageTag>${project.version}</imageTag>
<imageTag>latest</imageTag>
</imageTags>
<forceTags>true</forceTags>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
<dockerHost>http://192.168.147.130:2375</dockerHost>
</configuration>
</plugin>
- 运行容器
systemctl start firewalld
docker run --name demo -p "8081:8081" -d 192.168.147.130:5000/demo
systemctl stop firewalld
6、maven 项目配置 -- war 方式
- 创建目录
FROM daocloud.io/library/tomcat:8.5.15-jre8
MAINTAINER vim
WORKDIR /usr/local/tomcat/webapps
ARG JAR_FILE
ADD ${JAR_FILE} ${JAR_FILE}
- maven 配置,参考 springboot war 打包方式镜像配置
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.13</version>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<!-- <execution>
<id>push-image</id>
<phase>package</phase>
<goals>
<goal>push</goal>
</goals>
</execution>-->
</executions>
<configuration>
<imageName>${docker.registry}/${project.name}:${project.version}</imageName>
<imageTags>
<imageTag>${project.version}</imageTag>
<imageTag>latest</imageTag>
</imageTags>
<forceTags>true</forceTags>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.war</include>
</resource>
</resources>
<buildArgs>
<JAR_FILE>${project.build.finalName}.war</JAR_FILE>
</buildArgs>
<dockerHost>http://192.168.147.130:2375</dockerHost>
</configuration>
</plugin>
- 运行容器
systemctl start firewalld
docker run --name tomcat -p "8083:8080" -d 192.168.147.130:5000/demo
systemctl stop firewalld