英文:
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 ["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>
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 守护程序:
- 以管理员身份打开 Powershell
- 运行以下命令:
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:
- Open Powershell as administrator
- Run following command:
cd "C:\Program Files\Docker\Docker"
./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=<your home path>\.docker\machine\machines\default
SET DOCKER_MACHINE_NAME=default
SET COMPOSE_CONVERT_WINDOWS_PATHS=true```
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论