SpringBoot 远程打包Docker镜像

运行环境

远程环境 CentOS Linux 7
本地环境 Windows 10
Docker版本 1.13.1, build 774336d/1.13.1

开启docker远程连接

修改配置

vim /usr/lib/systemd/system/docker.service

在ExecStart后面 添加一行(表示启动2375端口 用于监听远程操作)

-H tcp://0.0.0.0:2375  -H unix:///var/run/docker.sock \

docker.service修改后部分展示

[Service]
Type=notify
NotifyAccess=main
EnvironmentFile=-/run/containers/registries.conf
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current \
          --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 \
          --init-path=/usr/libexec/docker/docker-init-current \
          --seccomp-profile=/etc/docker/seccomp.json \
          -H tcp://0.0.0.0:2375  -H unix:///var/run/docker.sock \
          $OPTIONS \
          $DOCKER_STORAGE_OPTIONS \
          $DOCKER_NETWORK_OPTIONS \
          $ADD_REGISTRY \
          $BLOCK_REGISTRY \
          $INSECURE_REGISTRY \
          $REGISTRIES
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576

重新加载配置文件

systemctl daemon-reload

重启服务

systemctl restart docker.service 

端口查看

netstat -nptl 

SpringBoot 远程打包Docker镜像_第1张图片
curl看是否生效

curl http://127.0.0.1:2375/info

SpringBoot 远程打包Docker镜像_第2张图片

修改pom.xml配置

 
   	   
   			org.springframework.boot
   			spring-boot-maven-plugin
   		 
   		
   			 org.apache.maven.plugins
   			 maven-deploy-plugin
   			 
   			 true
   			  
   		 
   		
   			com.spotify
   			dockerfile-maven-plugin
   			1.4.0
   			
   				${project.artifactId}
					
					${project.version}
   				
   					target/${project.build.finalName}.jar
   				
   			
   		
   

创建Dockerfile

FROM java:8

MAINTAINER [email protected]

WORKDIR /

ARG JAR_FILE

ADD ${JAR_FILE} app.jar

EXPOSE 58035

ENV TZ=Asia/Shanghai

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

ENTRYPOINT ["sh" ,"-c","java -Djava.security.egd=file:/dev/./urandom -jar app.jar"]

将Dockerfile放到项目根目录下
SpringBoot 远程打包Docker镜像_第3张图片

Eclipse构建

项目右键-> Run As -> Maven Build…
填写maven命令
clean package dockerfile:build
SpringBoot 远程打包Docker镜像_第4张图片
添加DOCKER_HOST
SpringBoot 远程打包Docker镜像_第5张图片
点击Run开始构建

你可能感兴趣的:(Spring,Boot,Docker)