我有一个maven项目,我正试图将其部署到Amazon Web Services的Elastic Beanstalk。我希望使用Docker文件进行部署。
在我的Windows PC上,Docker文件可以在本地运行,但在部署到Elastic Beanstalk时就不行了。我的项目结构如下所示:
~/my-project/
|-- Dockerfile
|-- src
|-- pom.xml这是我的Docker文件:
# Build stage
#
FROM maven:3.8.1-jdk-8 AS build
ADD src /tmp/src
ADD pom.xml /tmp/pom.xml
RUN mvn -f /tmp/pom.xml clean package
#
# Package stage
#
FROM openjdk:8
COPY --from=build /tmp/target/my-project-host-0.0.1-SNAPSHOT.jar /usr/local/lib/my-project.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/lib/my-project.jar"]要在本地使用和执行这个Docker文件,我所要做的就是从项目根目录运行这些命令,然后我的Springboot服务器就会启动并运行:
docker build -t image-my-project .
docker run -d -p 8080:8080 image-my-project现在问题来了。为什么在部署到AWS Elastic Beanstalk时会失败。
我将详细介绍如何将其部署到Elastic Beanstalk。
1) navigate to project root (my-project) and run the command:
a) eb create
b) this will prompt me with configuring the environment.
2) Set up environment with the following configs:
a) name of environment: my-project
a) load balancer type = 'application' (Should this be 'network' instead?)
3) After setting up the configs, the project begins to deploy but it always fails.如果我下载eb-engine.log文件,我会收到错误消息,指出docker无法拉取Maven。以下是日志文件部分:
start build docker app
2021/11/04 12:31:25.779536 [INFO] fetch image name
2021/11/04 12:31:25.779584 [INFO] pull docker image if update is not false in Dockerrun.aws.json
2021/11/04 12:31:25.779604 [INFO] Running command /bin/sh -c docker pull maven:3.8.1-jdk-8 AS build
2021/11/04 12:31:25.817783 [WARN] failed to execute command: docker pull maven:3.8.1-jdk-8 AS build, retrying...
2021/11/04 12:31:25.817814 [INFO] Running command /bin/sh -c docker pull maven:3.8.1-jdk-8 AS build
2021/11/04 12:31:25.859856 [ERROR] An error occurred during execution of command [app-deploy] - [Docker Specific Build Application]. Stop running the command. Error: failed to pull docker image: Command /bin/sh -c docker pull maven:3.8.1-jdk-8 AS build failed with error exit status 1. Stderr:"docker pull" requires exactly 1 argument.
See 'docker pull --help'.
Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Pull an image or a repository from a registry
2021/11/04 12:31:25.859878 [INFO] Executing cleanup logic
2021/11/04 12:31:25.859986 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed to download the Docker image. The deployment failed.","timestamp":1636029085,"severity":"ERROR"},{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1636029085,"severity":"ERROR"}]}]}
2021/11/04 12:31:25.860367 [INFO] Platform Engine finished execution on command: app-deploy有人知道这是怎么回事吗?为什么我的Docker文件可以在本地工作,但不能部署到AWS Elastic Beanstalk?
发布于 2021-11-04 13:07:30
我想明白了,所以我将给未来的读者留下一个答案。事实证明亚马逊网络服务不允许你在Docker中使用AS关键字。因此,我将文件更改为:
# Build stage
#
FROM maven:3.8.1-jdk-8 AS build
ADD src /tmp/src
ADD pom.xml /tmp/pom.xml
RUN mvn -f /tmp/pom.xml clean package
#
# Package stage
#
FROM openjdk:8
COPY --from=build /tmp/target/my-project-host-0.0.1-SNAPSHOT.jar /usr/local/lib/my-project.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/lib/my-project.jar"]要这样做:
# Build stage
#
FROM maven:3.8.1-jdk-8
ADD src /tmp/src
ADD pom.xml /tmp/pom.xml
RUN mvn -f /tmp/pom.xml clean package
#
# Package stage
#
FROM openjdk:8
COPY --from=0 /tmp/target/my-project-host-0.0.1-SNAPSHOT.jar /usr/local/lib/my-project.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/lib/my-project.jar"]https://stackoverflow.com/questions/69839572
复制相似问题