在ARM64的架构服务器上进行Docker的jar包镜像部署

本机是WIndows,AMD64架构的;目标Linux服务器是ARM64架构的Debian。进行jar包的容器部署方式。

目标服务器

root@localhost:~# uname -a
Linux localhost 5.10.0-11-arm64 #1 SMP Debian 5.10.92-2 (2022-02-28) aarch64 GNU/Linux
root@localhost:~# arch
aarch64

第1次尝试

Dockerfile

# 基础镜像
FROM openjdk:8-jdk-alpine

# 拷贝jar包
COPY ./target/arm64web-0.0.1-SNAPSHOT.jar /opt/arm64web-0.0.1-SNAPSHOT.jar

# 端口和工程启动的端口一致
EXPOSE 8080

# 运行命令
ENTRYPOINT ["java", "-jar", "-Duser.timezone=Asia/Shanghai", "/opt/arm64web-0.0.1-SNAPSHOT.jar"]
MAINTAINER yangliu

打包命令

# 打包命令
docker build -t arm64web:1.0 .

# 容器输出命令
docker save -o arm64web.tar arm64web:1.0

运行出错

root@localhost:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
arm64web     1.0       74d619bb615d   11 minutes ago   122MB
root@localhost:~# docker run -p 8080:8080 --name arm64web arm64web:1.0
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
exec /usr/bin/java: exec format error

第2次尝试

修改打包命令

docker buildx build --platform linux/arm64 -t arm64web:2.0 .

则运行成功

root@iZbp14skqirpwqnij2h78cZ:~# docker run -p 8080:8080 --name arm64web arm64web:2.0

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v2.7.7-SNAPSHOT)

2022-12-07 15:04:05.359  INFO 1 --- [           main] c.example.arm64web.Arm64webApplication   : Starting Arm64webApplication v0.0.1-SNAPSHOT using Java 1.8.0_212 on 12b5a97ab51d with PID 1 (/opt/arm64web-0.0.1-SNAPSHOT.jar started by root in /)
2022-12-07 15:04:05.363  INFO 1 --- [           main] c.example.arm64web.Arm64webApplication   : No active profile set, falling back to 1 default profile: "default"
2022-12-07 15:04:06.862  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-12-07 15:04:06.879  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-12-07 15:04:06.880  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.69]
2022-12-07 15:04:06.997  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-12-07 15:04:06.998  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1507 ms
2022-12-07 15:04:07.534  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-12-07 15:04:07.545  INFO 1 --- [           main] c.example.arm64web.Arm64webApplication   : Started Arm64webApplication in 2.927 seconds (JVM running for 3.513)
http://localhost:8080/test

你可能感兴趣的:(Docker,docker,架构,jar)