MAC 系统 用Docker 部署SpringBoot项目

1、今天有空看了一篇公众号docker 部署SpringBoot项目
2、刚好自己手上有spring boot 项目那就试下
3、不多说了那就干吧

1、先要有安装docker ,maven
1.2、拉取jdk1.8

docker pull java:8

2、安装好docker spring boot 项目的pom.xml文件需要加

 <properties>   <docker.image.prefix>registry.aliyuncs.com/linhuatest</docker.image.prefix>
    </properties>
<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                    <!--docker文件所在的目录-->
                    <dockerDirectory>src/main/docker</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>

    </build>

3、在spring boot 项目的main目录下建目录与文件夹在这里插入图片描述
docker file 内容如下

FROM java:8
VOLUME /tmp/tomcat
ADD oxx_datacenter_xxx-0.0.1-SNAPSHOT.jar springboot-docker.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/springboot-docker.jar"]

说明:FROM:指定存在的镜像,java:8是我刚刚拉取的镜像,运行的基础。VOLUME:指向的一个临时文件,用于存储tomcat工作。ADD:复制文件并且重命名文件。ENTRYPOINT:初始化配置或者自定义配置。

4、然后进入spring boot 目录下 cd
/Users/liyang/Downloads//oxx_datacenter_xxx

5、执行命令

mvn clean package docker:build

6、查看生成的docker 文件

docker images

在这里插入图片描述
7、运行文件(注意项目的端口号最好和你spring boot 中的 .yml一样)

docker run --name xxx_datacenter_xxx -p 28075:28075 -d c25b

8、查看起来了没有

docker ps

在这里插入图片描述
9、进入容器

docker exec -it 3cf2 /bin/bash

10、查看日志,这里的日志位置与你的spring boot中的log4j 配置的目录是一级的运行ok
参考的公众号地址:https://mp.weixin.qq.com/s/I-qREIU35QoV0tzCxB1hnQ

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值