在macOS上使用podman创建 Spring Boot 2.7 'mvnSpring引导:构建映像'失败

dffbzjpn  于 2022-11-05  发布在  Spring
关注(0)|答案(1)|浏览(254)

我尝试使用podman创建一个带有mvn spring-boot:build-image的图像,但得到

[INFO] --- spring-boot-maven-plugin:2.7.0:build-image (default-cli) @ sample-spring-service ---
[INFO] Building image 'docker.io/library/sample-spring-service:1.0.0-SNAPSHOT'
[INFO] 
[INFO]  > Pulling builder image 'docker.io/paketobuildpacks/builder:base' 100%
[INFO]  > Pulled builder image 'docker.io/paketobuildpacks/builder@sha256:94e65320ba1682bc68cbbf1d4f63693bb62cc06c7077bfa3e3bccac7fdc10628'
[INFO]  > Pulling run image 'docker.io/paketobuildpacks/run:base-cnb' 100%
[INFO]  > Pulled run image 'docker.io/paketobuildpacks/run@sha256:3e889016680c0e2ef1e8b1bfdad2d6d34966c860a53ccfcfb3e269d48ed65fed'
[INFO]  > Executing lifecycle version v0.14.1
[INFO]  > Using build cache volume 'pack-cache-744ddec35876.build'
[INFO] 
[INFO]  > Running creator
[INFO]     [creator]     ERROR: initializing analyzer: getting previous image: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/info": dial unix /var/run/docker.sock: connect: permission denied

波德曼信息:

host:
  arch: amd64
  buildahVersion: 1.26.1
  cgroupControllers:
...
version:
  APIVersion: 4.1.0
  Built: 1651853754
  BuiltTime: Fri May  6 18:15:54 2022
  GitCommit: ""
  GoVersion: go1.18
  Os: linux
  OsArch: linux/amd64
  Version: 4.1.0

我已经试过很多次了。在socket上设置权限,用root运行podman。用docker也是一样的,运行得很好。
podman create alpine ls工作正常。
在我的pom.xml中,我尝试:

<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <docker>
                    <!--  <host>unix:///Users/mike/.local/share/containers/podman/machine/podman-machine-default/podman.sock</host>
                        <host>unix:///run/user/1000/podman/podman.sock</host>
                    -->
                        <bindHostToBuilder>true</bindHostToBuilder>
                    </docker>
                </configuration>
            </plugin>

你知道吗?
更新:
如果我在pom.xml中启用这一行:
///执行/使用者/1000/鼠标器管理员/鼠标器管理员sock
我得到:

[INFO] --- spring-boot-maven-plugin:2.7.0:build-image (default-cli) @ sample-spring-service ---
[INFO] Building image 'docker.io/library/sample-spring-service:1.0.0-SNAPSHOT'
[INFO] 
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO]  > Pulling builder image 'docker.io/paketobuildpacks/builder:base' 100%
kokeuurv

kokeuurv1#

适用于遇到类似问题的用户,例如在使用远程Docker主机时
据我所知:

  • 拉取是使用pom.xml中的Docker参数或DOCKER_HOST之类的环境变量完成的
  • 拉取完成后,创建者将启动一个新容器,并在这个新容器中运行接下来的命令
  • 到新容器中的docker的连接可能不起作用,因为DOCKER_HOST可能需要不同的参数才能访问新容器中的docker。在“creator”容器中,/var/run/docker.sock会自动从主机系统挂载。
  • 如果启用bindHostToBuilder,它会将DOCKER_HOST(或pom.xml中的参数)传递给新容器,但这可能不是从新容器中可以访问的正确的Docker主机名。

对我来说,解决方案是不使用bindHostToBuilder,而是确保/var/run/docker.sock存在于主机系统上,以便可以在“creator”容器中Map它,即使拉操作是在不同的DOCKER_HOST(远程Docker)上进行的。

相关问题