win10 idea springboot上传镜像到远程docker服务器

1. 开启2375端口,供外部访问docker

vim /usr/lib/systemd/system/docker.service
修改ExecStart为下面一行内容
#ExecStart=/usr/bin/dockerd -H unix://
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
systemctl daemon-reload // 1,加载docker守护线程
systemctl restart docker // 2,重启docker

测试端口是否成功 curl 127.0.0.1:2375/info

在win10客户端添加环境变量

win10 idea springboot上传镜像到远程docker服务器_第1张图片

添加dos下mvn命令的执行

直接在Path属性后面添加一条当前Maven的文件地址加上\bin

2. 使用docker-maven-plugin插件上传镜像到docker服务器


        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
            
                com.spotify
                docker-maven-plugin
                1.0.0
                
                    ${project.name}:${project.version}
                    ${project.basedir}/src/main/docker
                    http://192.168.1.10:2375
                    
                        
                            /
                            ${project.build.directory}
                            ${project.build.finalName}.jar
                        
                    
                
            
        
    

3. 在src/main下面新建文件夹docker

添加文件Dockerfile

FROM daocloud.io/library/java:8u40-b22  #这里是巨坑,下载慢的话一定要关闭从新下载
VOLUME /tmp
ADD gexin-docker-demo-1.0-SNAPSHOT.jar app.jar
RUN sh -c 'touch /app.jar'
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

执行命令  mvn clean package docker:build

执行成功出现如下截图内容

win10 idea springboot上传镜像到远程docker服务器_第2张图片

报错如下:

1. No plugin found for prefix 'docker' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (F:\repo), nexus-aliyun (http://maven.aliyun.com/nexus/content/groups/public)] -> [Help 1]

  解决办法:在maven的conf/setting.xml中要加入


    
    com.spotify
  




    nexus-aliyun
    *
    Nexus aliyun
    http://maven.aliyun.com/nexus/content/groups/public

再次执行mvn clean package docker:build

 4. 登录虚拟机可以看到

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gexin-docker-demo 1.0-SNAPSHOT ac7ed71487ca 16 seconds ago 904MB
daocloud.io/library/java 8u40-b22 0a5e1e22983a 4 years ago 815MB
[root@localhost ~]# docker run -d -p 8091:8091 gexin-docker-demo:1.0-SNAPSHOT
bd87d64f71668c9e97eb99de6b8d50ae0a9ca2e80ad0da8081bc50cd000b345c
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bd87d64f7166 gexin-docker-demo:1.0-SNAPSHOT "sh -c 'java $JAVA_O…" 7 seconds ago Up 5 seconds 0.0.0.0:8091->8091/tcp confident_curran

在浏览器查看结果 http://192.168.1.10:8091/

总结:

1. 选择使用docker和dockerfile执行很重要

2. FROM 选择jdk很重要,可能造成下载过慢或者找不到包

转载于:https://www.cnblogs.com/mutong1228/p/10960693.html

你可能感兴趣的:(win10 idea springboot上传镜像到远程docker服务器)