intellij一键将项目部署到docker环境中

1.修改docker的配置文件,在ExecStart后面添加-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

[root@localhost ~]# vim /usr/lib/systemd/system/docker.service

修改后的文件如下

ExecStart=/usr/bin/dockerd-current -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock   \
          --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 \
          $OPTIONS \
          $DOCKER_STORAGE_OPTIONS \
          $DOCKER_NETWORK_OPTIONS \
          $ADD_REGISTRY \
          $BLOCK_REGISTRY \
          $INSECURE_REGISTRY \
          $REGISTRIES

2.重新加载配置文件

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start docker

运行结果如下图
在这里插入图片描述
3.向pom文件添加如下代码

   
              com.spotify
                    docker-maven-plugin
                    1.0.0
                    
                        
                            build-image
                            package
                            
                                build
                            
                        
                    
                    
                        dolphin/${project.artifactId}
                        
                            latest
                        
                        ${project.basedir}
                        http://172.16.10.196:2375
                        
                            
                                /
                                ${project.build.directory}
                                ${project.build.finalName}.jar
                            
                        
                        docker-hub
                        https://index.docker.io/v1
                    
                

4.在项目根目录下面加入如下的docker文件

FROM java:8
ADD target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]

5.maven clean package就将项目部署到服务器了,运行结果如下intellij一键将项目部署到docker环境中_第1张图片

你可能感兴趣的:(运维)