eureka-server打包在docker中运行

在项目src/main下,创建docker文件夹,再创建Dockerfile,pom文件也需要添加docker plugin(本文省略了eureka-server的创建,因为很简单的,可在网上随便搜索就能找到了)

pom.xml
<properties>
    ...
    <docker.image.prefix>springcloud</docker.image.prefix>
</properties>

<!-- Docker maven plugin -->
<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>1.0.0</version>
    <configuration>
        <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
        <dockerDirectory>src/main/docker</dockerDirectory>
        <resources>
            <resource>
                <targetPath>/</targetPath>
                <directory>${project.build.directory}</directory>
                <include>${project.build.finalName}.jar</include>
            </resource>
        </resources>
    </configuration>
</plugin>
Dockerfile:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD eureka-server-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

mvn package //打包

mvn package docker:build // 根据Dockerfile构建docker image

docker images查看新创建的image

docker run -p 7001:7001 -t [image name]
这样你在本地的docker就已经启动了eureka-server了

上传到服务器:

打包上传到阿里云,执行 docker save cchenlll/eureka-server -o /Users/cchenlll/eureka-server.tar 打包image到本地

上传到服务器后,在文件目录下执行 docker load -i eureka-server.tar 然后再运行image。
这种方式可能比较low哈哈,你也可以将构建好的镜像上传到镜像仓库,然后在服务器上将镜像拉取下来。

注意:需要在阿里云ecs中添加安全组

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容