Skip to content

Instantly share code, notes, and snippets.

@Seasawher
Last active August 23, 2023 11:31
Show Gist options
  • Save Seasawher/18f5781e372e4fbe691ee8942828bd8e to your computer and use it in GitHub Desktop.
Save Seasawher/18f5781e372e4fbe691ee8942828bd8e to your computer and use it in GitHub Desktop.
VSCode DevContainer でコンテナを立ち上げたときに,`unsafe repository` と言われて Git が無効にされる問題

VSCode DevContainer でコンテナを立ち上げたときに,unsafe repository と言われて Git が無効にされる問題

問題の概要

VSCode DevContainer でコンテナを立ち上げたときに,unsafe repository と言われて Git が無効にされます. Git Graph 拡張機能も無効にされます.

毎回コンテナを立ち上げてから手動で「安全です」とVSCodeに教える必要があり,手間がかかっていた.

解決策

devcontainer.jsonpostCreateCommand に次のように指定します.

「コンテナ作成の後に」実行されるのが重要.Dockerfile の RUN に書いても効果はありません.

{
    "name": "${localWorkspaceFolderBasename}",
    "build": {
        "dockerfile": "Dockerfile"
    },
    "onCreateCommand": "poetry install",
    "postCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}",
    "customizations": {
        "vscode": {}
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment