一、工程结构
二、Pom配置
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!-- tag::plugin[] --> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.3</version> <configuration> <imageName>${docker.image.prefix}/${project.artifactId}</imageName> <dockerDirectory>src/main/docker</dockerDirectory> <skipDockerBuild>false</skipDockerBuild> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> <!-- end::plugin[] --> </plugins> </build>
yml配置信息
server: port: 8661 # context-path: /hello eureka: instance: prefer-ip-address: true client: registerWithEureka: false fetchRegistry: false
三、dockerfile信息
创建dockerfile文件,位置:src/main/docker
FROM frolvlad/alpine-oraclejdk8:slim VOLUME /tmp ADD eureka-server-docker-0.0.1-SNAPSHOT.jar app.jar #RUN bash -c ‘touch /app.jar‘ ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] EXPOSE 8761
四、修改远程Linux服务器docker配置,作者版本为Centos7
1、编辑docker.service文件
vi /usr/lib/systemd/system/docker.service
在ExecStart这一行后面追加-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
ExecStart=/usr/bin/dockerd-current -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY
2、重启docker服务
service docker restart
3、查看端口是否启动
netstat -anp|grep 2375
4、防火墙开放2375端口
firewall-cmd --zone=public --add-port=2375/tcp --permanent
firewall-cmd --reload
五、Windows增加DOCKER_HOST环境变量
六、Maven打包构建
mvn clean package docker:build -DskipTests
七、启动容器
docker run --name eureka-server -p 8661:8661 -d mydocker/eureka-server-docker
八、访问测试
时间: 2024-11-03 13:24:53