DOCKER。使用Dockerfile创建镜像时出现错误。

huangapple go评论86阅读模式
英文:

DOCKER. Error when creating an image with dockerfile

问题

我需要将我的项目放入容器中。我使用 Intellij idea,并且所有的命令我都是在Intellij的终端中输入的。我使用的命令如下:

$ mvn package
$ docker build -f Dockerfile -t week10 .

镜像 hello-world 正常工作。
我创建了可执行的jar文件和Dockerfile。当我输入命令创建镜像时,我收到以下错误信息:

> 在连接期间发生错误:发布
> http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&do
> ckerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=jauqgloaecpwv5hch49bgfcak&shmsize=0&t=week10&target=&ulimits=null&version=1:
> 打开 //./pipe/docker_en gine:系统找不到指定的文件。
> 在Windows上的默认守护程序配置中,必须以提升的权限运行docker
> 客户端以进行连接。此错误还可能表示
> docker 守护程序未在运行。

Dockerfile:

FROM openjdk:8-jdk-alpine
ADD target/week10-1.0-SNAPSHOT.jar week10.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","week10.jar"]

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example</groupId>
    <artifactId>week10</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.2.6.RELEASE</version>
                <configuration>
                    <finalName>week10</finalName>
                    <mainClass>com.fruitshop.Application</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <properties>
        <start-class>com.fruitshop.Application</start-class>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <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>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
</project>

你可以在这里查看我的整个项目:Project

我不知道我做错了什么。请指出问题所在以及如何解决。

英文:

I need to containerize my project. I use Intellij idea and all command i write in the intellij terminal. Commands that I use:

$ mvn package
$ docker build -f Dockerfile -t week10 .

Image hello-world is working correctly.
I create executable jar and Dockerfile. When I enter the command to create image I get the following error:

> error during connect: Post
> http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&do
> ckerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=jauqgloaecpwv5hch49bgfcak&shmsize=0&t=week10&target=&ulimits=null&version=1:
> open //./pipe/docker_en gine: The system cannot find the file
> specified. In the default daemon configuration on Windows, the docker
> client must be run elevated to connect. This error may also indicate
> that the docker daemon is not running.

Dockerfile:

FROM openjdk:8-jdk-alpine
ADD target/week10-1.0-SNAPSHOT.jar week10.jar
EXPOSE 8080
ENTRYPOINT [&quot;java&quot;,&quot;-jar&quot;,&quot;week10.jar&quot;]

pom.xml

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;org.example&lt;/groupId&gt;
&lt;artifactId&gt;week10&lt;/artifactId&gt;
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&lt;packaging&gt;jar&lt;/packaging&gt;
&lt;parent&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
&lt;version&gt;2.2.5.RELEASE&lt;/version&gt;
&lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
&lt;/parent&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;2.2.6.RELEASE&lt;/version&gt;
&lt;configuration&gt;
&lt;finalName&gt;week10&lt;/finalName&gt;
&lt;mainClass&gt;com.fruitshop.Application&lt;/mainClass&gt;
&lt;/configuration&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;goals&gt;
&lt;goal&gt;repackage&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;properties&gt;
&lt;start-class&gt;com.fruitshop.Application&lt;/start-class&gt;
&lt;java.version&gt;1.8&lt;/java.version&gt;
&lt;/properties&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
&lt;scope&gt;runtime&lt;/scope&gt;
&lt;optional&gt;true&lt;/optional&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;mysql&lt;/groupId&gt;
&lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
&lt;scope&gt;runtime&lt;/scope&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/project&gt;

You can see my entire project here: Project

I don't know what i did wrong. Please indicate what the problem is and how I can solve it

答案1

得分: 1

错误不是由于 Dockerfile,而是与以下部分相关:

> 在 Windows 上默认的守护程序配置中,docker 客户端必须以提升权限运行才能连接

您可以按照以下步骤切换 Docker 守护程序:

  1. 以管理员身份打开 Powershell
  2. 运行以下命令:

cd "C:\Program Files\Docker\Docker" ./DockerCli.exe -SwitchDaemon

英文:

The error is not due to the Dockerfile it is related to that part:

> In the default daemon configuration on Windows, the docker client must
> be run elevated to connect

You can do this in order to switch Docker daemon:

  1. Open Powershell as administrator
  2. Run following command:

cd &quot;C:\Program Files\Docker\Docker&quot;
./DockerCli.exe -SwitchDaemon

答案2

得分: 1

我解决了这个错误。如果你遇到相同的错误,你需要在终端中输入以下命令:

Docker-machine env default

然后你需要输入在屏幕上显示的设置,例如:

SET DOCKER_HOST=tcp://192.168.99.100:2376
SET DOCKER_CERT_PATH=<你的主目录路径>\.docker\machine\machines\default
SET DOCKER_MACHINE_NAME=default
SET COMPOSE_CONVERT_WINDOWS_PATHS=true```
<details>
<summary>英文:</summary>
I resolved this error. If you have the same error, you need to enter this command in the terminal: 
``` Docker-machine env default```
and then you need to enter the sets, that you have displayed on the screen, example:
```SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.100:2376
SET DOCKER_CERT_PATH=&lt;your home path&gt;\.docker\machine\machines\default
SET DOCKER_MACHINE_NAME=default
SET COMPOSE_CONVERT_WINDOWS_PATHS=true```
</details>

huangapple
  • 本文由 发表于 2020年4月6日 22:36:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/61062268.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定