springboot项目打包docker镜像并且上传到阿里云远程仓库

springboot项目打包docker镜像并且上传到阿里云远程仓库

文章目录

  • springboot项目打包docker镜像并且上传到阿里云远程仓库
    • 1, docker开启远程访问
      • 1-1 笔者docker安装在ubnutu上(Ubuntu 15.04及更高版本)
    • 2, maven插件

1, docker开启远程访问

1-1 笔者docker安装在ubnutu上(Ubuntu 15.04及更高版本)

  1. 创建/etc/systemd/system/docker.service.d目录
sudo mkdir /etc/systemd/system/docker.service.d
  1. 创建一个/etc/systemd/system/docker.service.d/http-proxy.conf文件。
    sudo vim /etc/systemd/system/docker.service.d/http-proxy.conf
   [Service]
   ExecStart=
   ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
  1. 刷新配置
sudo systemctl daemon-reload
  1. 重新启动docker守护进程
sudo systemctl restart docker
  1. 重启docker
sudo systemctl restart docker

2, maven插件

  1. 版本信息等变量

    
    <docker-maven-plugin.version>1.2.0docker-maven-plugin.version>
    
    <docker.image.prifx>tiger-cloud-platformdocker.image.prifx>
    
    <docker.baseImage>mrsinham/alpine-oraclejdk8docker.baseImage>
    
    <docker.host>http://192.168.8.244:2375docker.host>
    
    <docker.volumes>/tmpdocker.volumes>
    
    <docker.java.security.egd>-Djava.security.egd=file:/dev/./urandomdocker.java.security.egd>
    
    <docker.java.opts>-Xms128m -Xmx128mdocker.java.opts>
    
    <docker.repository.url>registry.cn-beijing.aliyuncs.comdocker.repository.url>
    
    <docker.repository.namespace>itpengweidocker.repository.namespace>
    
    <docker.repository.serverId>itpengweidocker.repository.serverId>
    
  2. maven本地仓库变量指定阿里云远程仓库命名空间的访问密码

<servers>
     	<server>
     		   
           <id>itpengweiid>
           
           <username>xxxxusername>
           
           <password>xxxxpassword>
           <configuration>
           	
               <email>[email protected]email>
           configuration>
       server>
<servers/>
  1. mavne插件配置
<build>
      <plugins>
         <plugin>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-maven-pluginartifactId>
            <executions>
               <execution>
                  <goals>
                     <goal>repackagegoal>
                  goals>
               execution>
            executions>
         plugin>
         <plugin>
            <groupId>com.spotifygroupId>
            <artifactId>docker-maven-pluginartifactId>
            <configuration>
               <forceTags>trueforceTags>
						
               <pushImage>truepushImage>
							             <imageName>${docker.repository.url}/${docker.repository.namespace}/${docker.image.prifx}:${project.artifactId}imageName>
								
               <serverId>${docker.repository.serverId}serverId>
								
               <registryUrl>${docker.repository.url}registryUrl>
               
               <dockerHost>${docker.host}dockerHost>
								
               <baseImage>${docker.baseImage}baseImage>
								
               <volumes>${docker.volumes}volumes>
               <env>
                  <JAVA_OPTS>${docker.java.opts}JAVA_OPTS>
               env>
               <entryPoint>["sh","-c","java $JAVA_OPTS ${docker.java.security.egd} -jar /${project.build.finalName}.jar"]entryPoint>
               <resources>
                  <resource>
                     <targetPath>/targetPath>
                     <directory>${project.build.directory}directory>
                     <include>${project.build.finalName}.jarinclude>
                  resource>
               resources>
            configuration>
         plugin>
      plugins>
      <finalName>${project.artifactId}finalName>
   build>

4,验证

通过命令mvn clean package docker:build命令执行完就能看到docker中已经有镜像了,并且阿里远程仓库也有了

springboot项目打包docker镜像并且上传到阿里云远程仓库_第1张图片
springboot项目打包docker镜像并且上传到阿里云远程仓库_第2张图片

你可能感兴趣的:(docker,springboot)