Docker<四>开放远程连接,idea打包上传镜像启动服务

  1. 开放docker远程访问:
    vi /lib/systemd/system/docker.service
    在ExecStart=/usr/bin/dockerd -H 后面添加 tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock


    微信图片_20190816142833.png
  2. 刷新配置,重启服务:
    systemctl daemon-reload
    systemctl restart docker
    docker start registry
  3. idea pox.xml中配置:
    
        app
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
            
                org.mybatis.generator
                mybatis-generator-maven-plugin
                1.3.2
                
                    true
                    true
                
            
            
            
                com.spotify
                docker-maven-plugin
                0.4.13
                
                    
                    47.95.228.162:5001/${project.artifactId}:${project.version}
                    jdk1.8
                    ["java","-jar","/${project.build.finalName}.jar"]
                    
                        
                            /
                            ${project.build.directory}
                            ${project.build.finalName}.jar
                        
                    
                    http://47.95.228.162:2375
                
            
        
    
  1. idea打包上传镜像到服务器:(服务器上docker的远程连接端口一定要开放)
    mvn install
    mvn docker:build -DpushImage
  2. 服务器上查看:
    docker images
  3. 浏览器查看:
    http://47.95.228.162:5001/v2/_catalog
    微信图片_20190816145639.png
  4. 服务器上启动镜像
    docker run -di --name=wordpress -p 8099:8099 47.95.228.162:5001/wordpressport:0.0.1-SNAPSHOT
[root@iz2zegpdc9x4o0ir42a2upz ~]# docker images
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
47.95.228.162:5001/wordpressport   0.0.1-SNAPSHOT      42610e023c13        5 minutes ago       638MB
47.95.228.162:5001/jdk1.8          latest              b5984b02f4fb        5 hours ago         589MB
jdk1.8                             latest              b5984b02f4fb        5 hours ago         589MB
redis                              latest              f7302e4ab3a8        41 hours ago        98.2MB
nginx                              latest              4733136e5c3c        2 days ago          126MB
tomcat                             7-jre7              47c156f4d4e3        3 months ago        359MB
centos/mysql-57-centos7            latest              e35b3f7a4ea0        4 months ago        452MB
centos                             7                   9f38484d220f        5 months ago        202MB
registry                           latest              f32a97de94e1        5 months ago        25.8MB
tutum/centos                       latest              99a633ad346f        3 years ago         297MB
[root@iz2zegpdc9x4o0ir42a2upz ~]# docker run -di --name=wordpress -p 8099:8099 47.95.228.162:5001/wordpressport:0.0.1-SNAPSHOT
196d7e96b986c148c361d269f9bf51b495da91987dcf14a7f7e90b6dc8073d24
[root@iz2zegpdc9x4o0ir42a2upz ~]# 
  1. 查看jar包是否运行
[root@iz2zegpdc9x4o0ir42a2upz ~]# ps -aux|grep .jar
root     224207  0.3 10.5 1470276 107212 ?      Ssl  14:52   0:05 /docker-java-home/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root     226452 23.5 18.5 2256384 188908 ?      Ssl  15:16   0:26 java -jar /app.jar
root     226627  0.0  0.0 112708  1008 pts/0    R+   15:17   0:00 grep --color=auto .jar

已发现app.jar在运行,打开浏览器输入访问接口,测试是否开放了访问端口

  1. 查看日志文件
    docker logs -f 容器ID/容器名
    例如: docker logs -f wordpress

你可能感兴趣的:(Docker<四>开放远程连接,idea打包上传镜像启动服务)