docker - 有没有办法在 VSCode Devcontainers 中调试 PostCreateCommand?
问题描述
我目前遇到这个问题:
Command failed: /bin/sh -c ./.devcontainer/postCreateCommand.sh
哪一个是
"postCreateCommand": "./.devcontainer/postCreateCommand.sh",
从devcontainer.json
.
但是当我停用“postCreateCommand”并在创建容器后手动运行它时,该脚本有效。这让我想到,问题可能是脚本的路径。但事实也并非如此。因为只有一个 echo 命令的空脚本似乎可以工作。
脚本如下:
echo "Installing Developer Requirements"
apt-get update && apt-get install -y man git
pip3 install -r .devcontainer/dev_pip_requirements.txt
任何想法如何调试"PostCreateCommand"
?输出没有什么帮助,我不想开始将此项目简化为最小的工作示例。
我将 git 更改为在 Windows 上以 linux 文件结尾签出所有内容。我三重检查了 shell 脚本是否有 LF 结尾。所以这些也不应该是一个问题。(他们以前是)。
解决方案
我认为一个原因可能是用户没有足够的权限来执行apt-get update
命令。
将配置文件中的 ,更改remoteUser
为root
,devcontainer.json
应该允许在postCreateCommand.sh
使用 运行 shell 脚本时成功执行它bash
。
我已经尝试使用
python:3.8-slim-buster
Docker 映像,并non-root
在Dockerfile
.我已将以下内容添加到
./.devcontainer/devcontainer.json
:"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh", "remoteUser": "root",
我使用了以下内容
./.devcontainer/postCreateCommand.sh
:#!/usr/bin/env bash set -ex apt-get update && apt-get install -y man git && rm -rf /var/lib/apt/lists/* pip install --requirement ./.devcontainer/dev_pip_requirements.txt
一般root
不推荐用于生产环境。
这是有关的更多信息postCreateCommand
推荐阅读
- node.js - Prisma:使用具有非唯一字段的“where”进行更新?
- python - 我可以将运算符 +,-,/,* 分配给 python 中的字符串吗?
- javascript - Bootstrap 4 Card Carousel 未显示多个项目
- flutter - 当 Future Builder 处于 ConnectionState.waiting 时,Flutter App 卡住了
- visual-studio-2019 - 安装新更新后,Visual Studio 2019 Git 在提交和推送时显示“commit --allow-empty-message --file=-”消息。不再提交和推送
- browser - 无法从域向 localhost 发送请求(net::ERR_BLOCKED_BY_CLIENT 错误)
- javascript - 鼠标悬停变成文字
- reactjs - 无法渲染我做错了什么?
- javascript - 如何用剩余的缺失月份填充一组对象(总共 12 个月)
- google-sheets - 谷歌表格查询