docker - 如何使用 CMD 在 docker 容器中运行 terraform apply --auto-approve
问题描述
我正在尝试在我的 Windows 机器的 Docker 容器中运行 Terraform。我实际上成功地在 Docker 容器中运行 Terraform。但是,我想运行命令“terraform apply --auto-approve”而不是简单的“terraform apply”,这样 terraform 就不会要求确认应用更改。
我使用 AWS 作为提供商。我有一个自己编写的 dockerfile,它使用 hashcorp/terraform:light 作为基础镜像。
以下是我的dockerfile:
# Use an official HashiCorp Terraform runtime as a base image.
FROM hashicorp/terraform:light AS base
#To create working directory.
WORKDIR /trojanwall-infra
# To add contents to the working directory.
ADD . /trojanwall-infra
# Copy the contents.
COPY . /trojanwall-infra
# To check the current version of Hashicorp Terraform.
# Use the base image to create a packaged image.
FROM base AS package
#To add to the working directory.
WORKDIR /root/.aws
# To copy the AWS credentials to root folder.
COPY ./Key/aws/config /root/.aws
COPY ./Key/aws/credentials /root/.aws
# Use the packaged image to create a final image.
FROM package AS final
#To add to the working directory.
WORKDIR /trojanwall-infra
# To Run Terraform init and initialize.
RUN terraform init
#RUN command inside the container.
CMD ["plan"]
CMD ["apply"]
上面的 dockerfile 确实有效,但它会在作为 Docker 容器运行时询问“是”/“否”以进行确认。我想使用它有点如下:
#RUN command inside the container.
CMD ["apply", "--auto-approve"]
但它说这是一种无效的格式。猜 dockerfile 的 CMD 不能以这种方式运行多个命令。
任何人都可以提供一些见解并帮助我吗?
解决方案
您使用的是什么版本的 Terraform?我的版本 (0.14.8) 没有--auto-apply
选项,我在网络上的其他任何地方都看不到它。我怀疑你的意思是使用-auto-approve
,它应该按照你尝试的方式工作:
# ...
# RUN command inside the container.
CMD ["apply", "-auto-approve"]
推荐阅读
- python - Element removal in image
- r - 删除具有正值的列?
- c - 在c程序中找到一条线上的一个点,距该线上的某个点一定距离
- python - 如何不将索引转换为列?
- python - 我如何通过组合使用列表中的值 - pysimplegui
- firebase - 找不到正确的提供者
在此注册小部件上方 - python - 从python中的json文件中查找字符串匹配
- python - Subprocess unrecognized arguments but command works in terminal
- android - 无法使用 Firebase UI Recycler Adapter 在 Recycler 视图中加载内容
- excel - 具有多个 OR/AND 标准的 SUMIFS(使用单元格引用)