• docker打包,运行springboot


    1. 创建src/main/docker/Dockerfile

    2.Dockerfile内容为:

    FROM frolvlad/alpine-oraclejdk8:slim
    VOLUME /tmp
    ADD demo_test-0.0.1-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" ]

    2:pom.xml代码为:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.2.2.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.example</groupId>
        <artifactId>demo_test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>demo_test</name>
        <description>Demo project for Spring Boot</description>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <!--properties节点中设置docker镜像的前缀“springboot”-->  
            <docker.image.prefix>springboot</docker.image.prefix>
            <java.version>1.8</java.version>
            <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
                <!-- tag::plugin[] -->    
                <plugin>    
                    <groupId>com.spotify</groupId>    
                    <artifactId>docker-maven-plugin</artifactId>    
                    <version>1.0.0</version>    
                    <configuration>    
                        <imageName>test/demo_test</imageName>    
                        <dockerDirectory>src/main/docker</dockerDirectory>    
                        <resources>    
                            <resource>    
                                <targetPath>/</targetPath>    
                                <directory>${project.build.directory}</directory>    
                                <include>${project.build.finalName}.jar</include>    
                            </resource>    
                        </resources>    
                        <dockerHost>http://ip:2375</dockerHost>
                    </configuration>    
                </plugin>    
                <!-- end::plugin[] -->  
            </plugins>
        </build>
    
    </project>

    3:执行eclipse mvn :  package docker:build

    4:  生成镜像成功后,查看镜像

    docker images

    5. 查看所有容器

    docker ps 

    6. 运行springboot容器

    docker fun -id -p 8080:8080 -t test/demo_test

    7:重复生成镜像,导致有none,删除所有none镜像:

    参考:http://blog.51yip.com/cloud/1859.html

    $ docker stop $(docker ps -a | grep "Exited" | awk '{print $1 }')   //停止容器  

    $ docker rm $(docker ps -a | grep "Exited" | awk '{print $1 }')    //删除容器

    $ docker rmi $(docker images | grep "none" | awk '{print $3}')    //删除镜像 

     

     

  • 相关阅读:
    中国正在消失的老行当
    ie9 scrollbar中hover 高度增高的bug
    (替月光博客备份)百度百科:游荡在中国的窃贼
    严格模式下 W3C Strict 验证的几个注意事项
    [转]滤镜渐变使用 IE浏览器
    1.什么是串口?
    6.串口操作之API篇 GetCommTimeouts SetCommTimeouts
    5.串口操作之API篇 SetupComm GetCommState SetCommState
    TeeChart经验总结 13.Export之2.对象保存
    解决"手机存储暂不能使用""SIM卡存储暂不能使用"
  • 原文地址:https://www.cnblogs.com/panql341/p/12093525.html
Copyright © 2020-2023  润新知