本地Springboot项目打包成docker镜像并上传到云仓库的全流程

本文用于记录将自己开发的springboot运用打包成docker镜像

1.创建一个属于自己的springboot的运用能够正常访问的

2.利用IDEA 打包成为jar包(如图所示)

3.创建一个Dockerfile(注:Dockerfile没有后缀名)

Dockerfile中的内容如下

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG docker-demo
COPY docker-demo.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

  (注:COPY 后面的jar的名称 必须和IDEA打的项目的jar包名称一致,否则会导致镜像启动失败)

4.将dockerfile文件和生成好的jar 使用ftp工具上传到linux服务器 随便找个文件夹 放进去 jar和dockerfile在同级目录下(默认linux上已经安装了docker)

5.使用 docker build -t docker_doem:v1.0 .

  注:

    1、 最后面的这个 . 代表在当前目录下面寻找 dockerfile 文件

    2、docker_doem镜像名字

    3、v1.0版本

    4、初次构建可能要去下载jdk 镜像 耐心等待

6.打包完成就可以使用docker images 查看镜像了

7.镜像启动:docker run -d --name  "docker_test" -p 8080:8080

8.打包完成以后可以推送至阿里云镜像仓库 (详情查看阿里云官网有详细教程)

9:docker 常用指令

docker ps :查看所有运行的容器

docker ps -a :查看所有容器包括死掉的

docker logs [容器id]  :查看启动失败的原因

docker images : 查看所有的镜像

docker rm  [容器名称]:删除容器

docker rmi [镜像id] : 删除镜像

docker start [容器名称] :启动容器

docker stop [容器名称]:停止指定的容器

docker run - d --name " [容器名称]" -p [宿主机暴露的端口]:[程序内部暴露的端口]  [镜像id]

docker inspect 容器名称  :检查容器内部情况

转载于:https://www.cnblogs.com/huangzhimin/p/11433789.html

`docker-maven-plugin` 是 Maven 插件之一,用于将 Java 应用程序,包括基于 Spring Boot 的项目,构建为 Docker 镜像。以下是使用这个插件将应用打包推送到私有仓库的基本步骤: 1. **添加插件依赖**:首先,在 `pom.xml` 文件的 `<build>` 标签内添加 `docker-maven-plugin` 的依赖配置,例如: ```xml <plugins> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.15</version> <!-- 更新到最新版本 --> </plugin> </plugins> ``` 2. **配置镜像信息**:在 `<project>` 节点下设置 Dockerfile 相关的配置,如镜像名称、标签、基础镜像等。这里假设你有一个名为 `application.jar` 的主程序包文件: ```xml <build> <plugins> <plugin> <configuration> <imageName>${project.artifactId}</imageName> <imageTags> <tag>${project.version}</tag> <tag>latest</tag> <!-- 如果需要常量更新的标签 --> </imageTags> <baseImage>openjdk:8-jdk-alpine</baseImage> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> </plugins> </build> ``` 3. **私有仓库配置**:如果你有一个私有Docker注册表(如JFrog Artifactory),你需要配置 Maven 的 Docker 接口,通常通过环境变量 `DOCKER_REGISTRY_URL` 和 `DOCKER_USERNAME`、`DOCKER_PASSWORD` 或者认证密钥: ```xml <profiles> <profile> <id>docker-push</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <dockerPushRepository>your-private-repo:5000</dockerPushRepository> <!-- 替换为你的私有仓库地址 --> </properties> <build> <plugins> <plugin> <executions> <execution> <goals> <goal>push</goal> </goals> <phase>deploy</phase> </execution> </executions> <configuration> <registryUrl>${dockerPushRepository}</registryUrl> <username>your-docker-registry-username</username> <password>your-docker-registry-password</password> <!-- 或者从安全环境下获取密钥 --> </configuration> </plugin> </plugins> </build> </profile> </profiles> ``` 4. **构建和推送镜像**:运行 `mvn clean package docker:build docker:push -Pdocker-push` 来构建推送镜像
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值