【发布时间】:2021-08-25 00:23:51
【问题描述】:
我正在尝试使用 docker 将我的 create-react-app 部署到弹性豆茎 我已经使用 codebuild 和弹性 beanstalk 设置了 codepipeline。
我收到了这个错误
Stop running the command. Error: Dockerfile and Dockerrun.aws.json are both missing, abort deployment
我的 Dockerfile 看起来像这样
FROM tiangolo/node-frontend:10 as build-stage
# Create app directory
# RUN mkdir -p /usr/src/app
# WORKDIR /usr/src/app
WORKDIR /app
# # fix npm private module
# ARG NPM_TOKEN
# COPY .npmrc /app/
#COPY package.json package.json
COPY package*.json /app/
COPY Dockerrun.aws.json /app/
RUN npm install
COPY ./ /app/
# RUN CI=true npm test
RUN npm run build
# FROM nginx:1.15
FROM nginx:1.13.3-alpine
# Install app dependencies
# Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx
COPY --from=build-stage /app/build/ /usr/share/nginx/html
# Copy the default nginx.conf provided by tiangolo/node-frontend
COPY --from=build-stage /nginx.conf /etc/nginx/conf.d/default.conf
RUN ls
EXPOSE 80
我也有一个 Dockerrun.aws.json
{
"AWSEBDockerrunVersion": "3",
"Image": {
"Name": "something.dkr.ecr.us-east-2.amazonaws.com/subscribili:latest",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "5000"
}
],
"Logging": "/var/log/nginx"
}
我的 buildspec.yml 文件如下所示
version: 0.2
phases:
pre_build:
commands:
- $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
- REPOSITORY_URI=something.dkr.ecr.us-east-2.amazonaws.com/subscribili
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_HASH:=latest}
build:
commands:
- docker build -t $REPOSITORY_URI:latest .
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
post_build:
commands:
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG
- printf '[{"name":"nginx","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
artifacts:
files: imagedefinitions.json
我确定 buildspec 文件存在一些问题,但我不确定是什么问题。
我已经阅读了所有文档,仍然无法弄清楚如何编写构建规范文件 Docker。 我有什么遗漏吗?
【问题讨论】:
-
你只有一个神器
imagedefinitions.json?那么其他所有内容,即错误消息中的文件呢? -
@Marcin 那里需要什么?
-
Dockerfile 和 Dockerrun.aws.json 这两个文件需要位于运行命令“COPY Dockerrun.aws.json /app/”的同一目录中。
标签: reactjs amazon-web-services dockerfile amazon-elastic-beanstalk aws-codepipeline