spring could Windows打包構建docker鏡像到linux

來源:互聯網
上載者:User

標籤:start   ane   分享   sock   火牆   建立   pat   rman   java   

一、工程結構

 

二、Pom配置

<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>0.4.3</version>                <configuration>                    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>                    <dockerDirectory>src/main/docker</dockerDirectory>                    <skipDockerBuild>false</skipDockerBuild>                    <resources>                        <resource>                            <targetPath>/</targetPath>                            <directory>${project.build.directory}</directory>                            <include>${project.build.finalName}.jar</include>                        </resource>                    </resources>                </configuration>            </plugin>            <!-- end::plugin[] -->        </plugins>    </build>

yml配置資訊

server:  port: 8661#  context-path: /helloeureka:  instance:    prefer-ip-address: true  client:    registerWithEureka: false    fetchRegistry: false

三、dockerfile資訊

建立dockerfile檔案,位置:src/main/docker

FROM frolvlad/alpine-oraclejdk8:slimVOLUME /tmpADD eureka-server-docker-0.0.1-SNAPSHOT.jar app.jar#RUN bash -c ‘touch /app.jar‘ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]EXPOSE 8761

四、修改遠程Linux伺服器docker配置,作者版本為Centos7

1、編輯docker.service檔案

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

在ExecStart這一行後面追加-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

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           $OPTIONS           $DOCKER_STORAGE_OPTIONS           $DOCKER_NETWORK_OPTIONS           $ADD_REGISTRY           $BLOCK_REGISTRY           $INSECURE_REGISTRY

2、重啟docker服務

service docker restart

3、查看連接埠是否啟動

netstat -anp|grep 2375

4、防火牆開放2375連接埠

firewall-cmd --zone=public --add-port=2375/tcp --permanent

firewall-cmd --reload

五、Windows增加DOCKER_HOST環境變數

六、Maven打包構建

     mvn clean package docker:build -DskipTests

七、啟動容器

docker run --name eureka-server -p 8661:8661 -d mydocker/eureka-server-docker

八、訪問測試

 

spring could Windows打包構建docker鏡像到linux

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.