Docker Win10 遇到的坑

环境信息

pom


<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.0modelVersion>
    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.3.2.RELEASEversion>
        <relativePath/> 
    parent>
    <groupId>com.tangsmgroupId>
    <artifactId>spring-boot-demoartifactId>
    <version>1.0-SNAPSHOTversion>
    <name>spring-boot-demoname>
    <description>Demo project for Spring Bootdescription>

    <properties>
        <java.version>1.8java.version>
        <docker.image.prefix>registry.aliyuncs.com/linhuatestdocker.image.prefix>
    properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-actuatorartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintagegroupId>
                    <artifactId>junit-vintage-engineartifactId>
                exclusion>
            exclusions>
        dependency>
    dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
            
            <plugin>
                <groupId>com.spotifygroupId>
                <artifactId>docker-maven-pluginartifactId>
                <version>1.0.0version>
                <configuration>
                    <imageName>${docker.image.prefix}/${project.artifactId}imageName>
                    
                    <dockerDirectory>src/main/dockerdockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/targetPath>
                            <directory>${project.build.directory}directory>
                            <include>${project.build.finalName}.jarinclude>
                        resource>
                    resources>
                configuration>
            plugin>
        plugins>
    build>

project>

dockerfile

FROM java:8
VOLUME /tmp/tomcat
ADD spring-boot-demo-1.0-SNAPSHOT.jar springboot-docker.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/springboot-docker.jar"]

问题一:打包docker镜像报错,2375端口问题

【Docker】在本地打包maven程序为docker镜像报错: Connect to localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1]

错误信息:

[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project farm: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect -> [Help 1]

我的错误原因是我没有打开本地的docker 2375端口

打开方式:右击右下角的小鲸鱼(我用的是docker for window),点击settings => General 勾选“Expose daemon on tcp://localhost:2375 without TLS”

如下图

Docker Win10 遇到的坑_第1张图片

问题二、访问国外docker hub仓库,获取镜像失败

# maven清理打包并构建docker镜像
mvn clean package docker:build

# Spring Boot 2.3.0.M1直接支持Maven和Gradle的buildpack
mvn spring-boot:build-image

拉取镜像或者本地打包上传镜像报以下错误

Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

此错误因为国内网络不能访问国外docker hub仓库引起的,需要配置国内镜像仓库,点击settings => Docker Engine 填入如下内容:

{
     
  "registry-mirrors": [
      "https://registry.docker-cn.com",
      "http://hub-mirror.c.163.com"
  ],
  "insecure-registries": [],
  "debug": true,
  "experimental": false
}

如图

Docker Win10 遇到的坑_第2张图片

参考

冰河团队:https://www.cnblogs.com/binghe001/p/12885714.html

你可能感兴趣的:(积累,docker,maven)