使用 Spring Boot Gradle 插件和 Colima 构建 Docker 映像

发布于 2025-01-16 22:25:17 字数 492 浏览 0 评论 0 原文

我正在尝试使用 Gradle 插件创建 Spring Boot 应用程序的 docker 映像。我正在使用 Spring Boot 2.6.4 和 Gradle 7.1.1。

我使用的是 Mac,并且没有安装 Docker Desktop。事实上,我使用 Colima 运行 docker。

问题是我无法使用命令 ./gradlew bootBuildImage 构建 docker 映像,因为 Gradle 找不到 docker 守护进程:

Connection to the Docker daemon at 'localhost' failed with error "[2] No such file or directory"; ensure the Docker daemon is running and accessible

是否有我必须在 Colima 或我的 build.gradle 中进行的配置 文件?

I'm trying to create a docker image of a Spring Boot application using the Gradle plugin. I'm using Spring Boot 2.6.4 and Gradle 7.1.1.

I'm on a Mac, and I don't have Docker Desktop installed. Indeed, I run docker using Colima.

The problem is that I cannot build the docker image with the command ./gradlew bootBuildImage since Gradle cannot find the docker daemon:

Connection to the Docker daemon at 'localhost' failed with error "[2] No such file or directory"; ensure the Docker daemon is running and accessible

Is there any configuration I have to do in Colima or my build.gradle file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弃爱 2025-01-23 22:25:17

Colima 默认在 ~/.colima/docker.sock 位置创建一个套接字。运行命令 docker context ls 应显示一个名为 colima 的上下文,其中套接字位置显示在 DOCKER ENDPOINT 列中。

您可以通过将 DOCKER_HOST 环境变量设置为 unix:///Users//.colima/docker.sock 将 Spring Boot Gradle 插件配置为使用此套接字> 或者将以下内容添加到构建文件中,如 文档

tasks.named("bootBuildImage") {
  docker {
    host = "unix:///Users/<user>/.colima/docker.sock"
  }
}

Colima creates a socket in the location ~/.colima/docker.sock by default. Running the command docker context ls should show a context named colima with the socket location shown in the DOCKER ENDPOINT column.

You can configure the Spring Boot Gradle plugin to use this socket by setting the DOCKER_HOST environment variable to unix:///Users/<user>/.colima/docker.sock or by adding the following to your build file as shown in the documentation.

tasks.named("bootBuildImage") {
  docker {
    host = "unix:///Users/<user>/.colima/docker.sock"
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文