我正在try 自动化在Docker容器中构建Reaction应用程序,然后使用Dockerfile中的AWS CLI将构建构件上载到S3存储桶的过程.然而,我在try 运行docker-compose up
时遇到错误
这是我的Dockerfile:
FROM node:16 as builder
WORKDIR /app
COPY package*.json ./
# Install dependencies
RUN npm install
COPY . .
RUN npm run build
# Use AWS CLI version 2 image for uploading to S3
FROM amazon/aws-cli:2.4.9
# Copy the build artifacts from the builder stage to this new stage
COPY --from=builder /app/build /build
# The bucket name and (optional) path where you want to upload the build files
ENV BUCKET_NAME=product-build
# Run AWS CLI command to sync files to your S3 bucket
CMD ["sh", "-c", "aws s3 sync /build s3://${BUCKET_NAME} --delete"]
这是我的docker-compose.yml:
version: '3.3'
services:
product-build:
build: ./
volumes:
- ./:/app
env_file:
- .env
stdin_open: true
我的.env文件包含:
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=
当我运行docker-compose build
时,构建过程似乎成功完成.但是,在运行docker-compose up
时,容器无法启动,并出现以下错误:
Container react-app-product-build-1 Recreate
Container react-app-product-build-1 Recreated
Attaching to react-app-product-build-1
react-app-product-build-1 |
react-app-product-build-1 | usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
react-app-product-build-1 | To see help text, you can run:
react-app-product-build-1 |
react-app-product-build-1 | aws help
react-app-product-build-1 | aws <command> help
react-app-product-build-1 | aws <command> <subcommand> help
react-app-product-build-1 |
react-app-product-build-1 | aws: error: argument command: Invalid choice, valid choices are: [list of valid AWS CLI commands]
react-app-product-build-1 exited with code 252
AWS CLI似乎无法在Docker容器中正确识别该命令,尽管它应该是可用的.如何使用Dockerfile中的AWS CLI解决此问题并将构建成果成功上传到S3?
提前感谢您能提供的任何见解或解决方案!