6

When launching an attached container in "VS Code Remote Development", has anyone found a way to change the container's shell when launching the vscode integrated terminal.

It seems to run something similar to.

docker exec -it <containername> /bin/bash

I am looking for the equivalent of

docker exec -it <containername> /bin/zsh

The only settings I found for Attached containers are

"remote.containers.defaultExtensions": []
customcommander
  • 17,580
  • 5
  • 58
  • 84
Bill Grant
  • 91
  • 1
  • 5
  • 1
    Possible duplicate of [How do I configure a different shell for a VS Code SSH Remote?](https://stackoverflow.com/questions/55978281/how-do-i-configure-a-different-shell-for-a-vs-code-ssh-remote) – Matt Bierner May 14 '19 at 01:20

4 Answers4

4

I'd like to contribute to this thread since I spent a decent amount of time combing the web for a good solution to this involving VS Code's new API for terminal.integrated.profiles.linux

Note as of 20 Jan 2022 both the commented and the uncommented json work. The uncommented out lines is the new non deprecated way to get this working with Dev containers.

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

if any one is interested I also figured out how to get oh my ZSH built into the image.

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
snekcode
  • 91
  • 4
  • Perfect, thanks. Just setting `terminal.integrated.defaultProfile.linux` worked for me, there seem to be good defaults for `terminal.integrated.profiles.linux` (and the `path` can be just a command rather than an absolute path). – Hal Jan 29 '22 at 16:31
3

I worked around it with

RUN echo "if [ -t 1 ]; then" >> /root/.bashrc
RUN echo "exec zsh" >> /root/.bashrc
RUN echo "fi" >> /root/.bashrc

Still would be interested in knowing if there was a way to set this per container.

Bill Grant
  • 91
  • 1
  • 5
2

I use a Docker container for my development environment and set the shell to bash in my Dockerfile:

# …
ENTRYPOINT ["bash"]

Yet when VS Code was connecting to my container it was insisting on using the /bin/ash shell which was driving me crazy... However the fix (at least for me) was very simple but not obvious:

enter image description here

From the .devcontainer.json reference.

All I needed to do in my case was to add the following entry in my .devcontainer.json file:

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

Complete .devcontainer.json file (FYI)

{
  "name": "project-blueprint",
  "dockerComposeFile": "./docker-compose.yml",
  "service": "dev",
  "workspaceFolder": "/workspace/dev",
  "postCreateCommand": "yarn",
  "settings": {
    "terminal.integrated.shell.*": "/bin/bash"
  }
}
customcommander
  • 17,580
  • 5
  • 58
  • 84
  • 7
    This setting doesn't work for me anymore. Here's the new version that does: ` "settings": { "terminal.integrated.defaultProfile.linux": "bash", "terminal.integrated.profiles.linux": { "bash": { "path": "bash" } } } ` – Jessitron Aug 13 '21 at 01:31
  • 2
    How do you have zsh as your default shell? – Jeff Jan 26 '22 at 06:54
1

2023 update - in devcontainer.json, settings now need to be nested under {'customizations': {'vscode': {'settings': {}}}}

Example:

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

https://containers.dev/supporting