我喜欢Docker环境工具,但我也希望能够在用户使用Docker环境工具克隆存储库时预装一些工具。
我在存储库中有一个带有.devcontainer的Dockerfile文件夹
# [Choice] Alpine version: 3.13, 3.12, 3.11, 3.10
ARG VARIANT="3.13"
FROM mcr.microsoft.com/vscode/devcontainers/base:0-alpine-${VARIANT}
# Install Terraform CLI
# Install GCloud SDK和一个devcontainer.json文件:
{
"name": "Alpine",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick an Alpine version: 3.10, 3.11, 3.12, 3.13
"args": { "VARIANT": "3.13" }
},
// Set *default* container specific settings.json values on container create.
"settings": {},
// Add the IDs of extensions you want installed when the container is created.
// Note that some extensions may not work in Alpine Linux. See https://aka.ms/vscode-remote/linux.
"extensions": [],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",
// Uncomment when using a ptrace-based debugger like C++, Go, and Rust
// "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}我尝试过将curl和安装命令包括在Dockerfile中,但是这些命令似乎不起作用。澄清一下,一旦容器被构建,我似乎无法访问CLI工具。terraform --version说没有找到地形。
对接器作为运行在容器中的VSCode窗口启动,如果这有区别的话,我将尝试使用来自VSCode终端的CLI工具。
发布于 2021-07-23 04:28:49
编辑:因此问题是,从Docker仪表板创建一个环境不会读取您的
.devcontainer文件夹和文件,它会创建一个基本库存容器。您需要克隆在VSCode中打开的存储库,然后是Reopen in Container,它将构建您的环境。
我换到Ubuntu作为基本映像,而不是从Docker仪表板创建dev环境,而是在VSCode中本地打开项目文件夹,并选择“在容器中重新打开”。那时,它似乎安装了所有的东西,我现在有了CLI工具。
下面的安装命令来自每个提供程序的正式文档。我将重新测试如何通过Docker仪表板将存储库拉下来,以查看它是否有效。
# [Choice] Ubuntu version: bionic, focal
ARG VARIANT="focal"
FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}
# Installs Terragrunt + Terraform
ARG TERRAGRUNT_PATH=/bin/terragrunt
ARG TERRAGRUNT_VERSION=0.31.1
RUN wget https://github.com/gruntwork-io/terragrunt/releases/download/v${TERRAGRUNT_VERSION}/terragrunt_linux_amd64 -O ${TERRAGRUNT_PATH} \
&& chmod 755 ${TERRAGRUNT_PATH}
# Installs GCloud SDK
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update -y && apt-get install google-cloud-sdk -yhttps://stackoverflow.com/questions/68493941
复制相似问题