Visual Studio Code Remote - 容器 - 更改 shell

问题描述 投票:0回答:4

在“VS Code远程开发”中启动附加容器时,有没有人找到在启动vscode集成终端时更改容器外壳的方法。

它似乎运行类似的东西。

docker exec -it <containername> /bin/bash

我正在寻找相当于

docker exec -it <containername> /bin/zsh

我发现的附加容器的唯一设置是

"remote.containers.defaultExtensions": []
docker visual-studio-code vscode-remote
4个回答
20
投票

2023 更新 - 在 devcontainer.json 中,设置现在需要嵌套在

{'customizations': {'vscode': {'settings': {}}}}

示例:

"customizations": {
        "vscode": {
            "settings": {
                "terminal.integrated.defaultProfile.linux": "zsh",
                "terminal.integrated.profiles.linux": { "zsh": { "path": "/bin/zsh" } }
            }
        }
    },

https://containers.dev/supporting


6
投票

我想为这个线程做出贡献,因为我花了相当多的时间在网络上进行梳理,寻找一个好的解决方案,涉及 VS Code 的新 API forterminal.integrated.profiles.linux

请注意,截至 2022 年 1 月 20 日,已注释和未注释的 json 均有效。 未注释的行是在开发容器中使用的新的、未弃用的方法。

{
    "settings": { 
        // "terminal.integrated.shell.linux": "/bin/zsh"
        "terminal.integrated.defaultProfile.linux": "zsh", 
        "terminal.integrated.profiles.linux": {
            "zsh": {
                "path": "/bin/zsh"
            },
        }
    }
}

如果有人感兴趣,我还想出了如何将我的 ZSH 内置到图像中。

Dockerfile:

# Setup Stage - set up the ZSH environment for optimal developer experience
FROM node:16-alpine AS setup

RUN npm install -g expo-cli
# Let scripts know we're running in Docker (useful for containerized development)
ENV RUNNING_IN_DOCKER true
# Use the unprivileged `node` user (pre-created by the Node image) for safety (and because it has permission to install modules)
RUN mkdir -p /app \
    && chown -R node:node /app
# Set up ZSH and our preferred terminal environment for containers
RUN apk --no-cache add zsh curl git
# Set up ZSH as the unprivileged user (we just need to start it, it'll initialize our setup itself)
USER node
# set up oh my zsh
RUN cd ~ && wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh && sh install.sh
# initialize ZSH
RUN /bin/zsh ~/.zshrc

# Switch back to root
USER root

4
投票

我用

解决了这个问题
RUN echo "if [ -t 1 ]; then" >> /root/.bashrc
RUN echo "exec zsh" >> /root/.bashrc
RUN echo "fi" >> /root/.bashrc

仍然有兴趣知道是否有办法为每个容器设置它。


3
投票

我使用 Docker 容器作为我的开发环境,并在我的 Dockerfile 中将 shell 设置为

bash

# …
ENTRYPOINT ["bash"]

然而,当 VS Code 连接到我的容器时,它坚持使用

/bin/ash
shell,这让我发疯......但是修复(至少对我来说)非常简单,但并不明显:

enter image description here

来自

.devcontainer.json
参考

在我的情况下,我需要做的就是在我的

.devcontainer.json
文件中添加以下条目:

{
  …
  "settings": {
    "terminal.integrated.shell.*": "/bin/bash"
  }
  …
}

完整

.devcontainer.json
文件(仅供参考)

{
  "name": "project-blueprint",
  "dockerComposeFile": "./docker-compose.yml",
  "service": "dev",
  "workspaceFolder": "/workspace/dev",
  "postCreateCommand": "yarn",
  "settings": {
    "terminal.integrated.shell.*": "/bin/bash"
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.