在 Docker 运行容器的时候,发现容器无法启动,通过 docker logs 指令查看到了如下的错误: standard_init_linux.go:211: exec user process caused “no such file or directory”
这个错误其实是 docker 镜像的平台和宿主机的平台架构不一致引起的,如你拉取的镜像是 amd64 平台的,但宿主机是 arm64 架构,就会产生该问题
那么如何解决这个错误呢,直入正题:
Maven 方式
我的项目基于 maven 构建,构建配置如下: 我打包的 maven 镜像默认是 amd64 版本的,只需要把 properties 的 jib-maven-plugin.architecture 改成 arm64 版本即可
<properties>
<java.version>1.8</java.version>
<jib-maven-plugin.version>3.1.4</jib-maven-plugin.version>
<jib-maven-plugin.image>eclipse-temurin:11-jre-focal</jib-maven-plugin.image>
<jib-maven-plugin.architecture>arm64</jib-maven-plugin.architecture>
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
</properties>
<build>
<defaultGoal>spring-boot:run</defaultGoal>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>${jib-maven-plugin.version}</version>
<configuration>
<from>
<image>${jib-maven-plugin.image}</image>
<platforms>
<platform>
<architecture>${jib-maven-plugin.architecture}</architecture>
<os>linux</os>
</platform>
</platforms>
</from>
<to>
<image>registry.dg.com/d4/foshan:latest</image>
<tags>
<tag>latest</tag>
<tag>${version}</tag>
</tags>
</to>
<container>
<entrypoint>
<shell>bash</shell>
<option>-c</option>
<arg>/entrypoint.sh</arg>
</entrypoint>
<ports>
<port>8080</port>
</ports>
<environment>
<SPRING_OUTPUT_ANSI_ENABLED>ALWAYS</SPRING_OUTPUT_ANSI_ENABLED>
<JHIPSTER_SLEEP>0</JHIPSTER_SLEEP>
</environment>
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
<user>1000</user>
</container>
<extraDirectories>
<paths>src/main/docker/jib</paths>
<permissions>
<permission>
<file>/entrypoint.sh</file>
<mode>755</mode>
</permission>
</permissions>
</extraDirectories>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<executions>
<execution>
<id>default-war</id>
<goals>
<goal>war</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<warSourceIncludes>WEB-INF/**,META-INF/**</warSourceIncludes>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warSourceDirectory>target/classes/static/</warSourceDirectory>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<includes>
<include>WEB-INF/**</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
docker build 方式
通过 --platform 参数指定
docker build --platform=linux/arm64 -t your_container_name:your_tag .
如果你想运行的官方镜像没有对应的系统架构,可以参考我的另一篇博文: https://blog.csdn.net/Vampire69/article/details/124457204
|