Correct me if I'm wrong. You want to have the ll alias available inside the container.
You can achieve this by:
- Adding this to the Dockerfile:
RUN echo "alias ll='ls -alF'" >> /etc/bash.bashrc
If you want to leave the Dockerfile as is:
Use the postCreateCommand from vscode (If you don't want to change the dockerfile):
"postCreateCommand": "echo alias ll=\\'ls -alF\\' >> /etc/bash.bashrc"This will add the alias directly to the system-wide bashrc file. The alias will be available in all interactive shells started within the container.OR
"postCreateCommand": "echo alias ll=\\'ls -alF\\' >> ~/.bash_aliases"This adds the alias to a separate file specifically for aliases and doesn't require root access in the container. Be aware: You'll need to source the .bash_aliases in .bashrc or else this won't work.(credit: @user317808)
If you run into a "Permission denied" then you can also do this:
"postCreateCommand": "echo alias ll=\\'ls -alF\\' >> /home/vscode/.bashrc" (credit: @Damian)
Correct me if I'm wrong. You want to have the ll alias available inside the container.
You can achieve this by:
- Adding this to the Dockerfile:
RUN echo "alias ll='ls -alF'" >> /etc/bash.bashrc
If you want to leave the Dockerfile as is:
Use the postCreateCommand from vscode (If you don't want to change the dockerfile):
"postCreateCommand": "echo alias ll=\\'ls -alF\\' >> /etc/bash.bashrc"This will add the alias directly to the system-wide bashrc file. The alias will be available in all interactive shells started within the container.OR
"postCreateCommand": "echo alias ll=\\'ls -alF\\' >> ~/.bash_aliases"This adds the alias to a separate file specifically for aliases and doesn't require root access in the container. Be aware: You'll need to source the .bash_aliases in .bashrc or else this won't work.(credit: @user317808)
If you run into a "Permission denied" then you can also do this:
"postCreateCommand": "echo alias ll=\\'ls -alF\\' >> /home/vscode/.bashrc" (credit: @Damian)
If you are using Dockerfile as part of your devcontainer setup you could have a file called devcontainer.bashrc that you move into the home folder in your Dockerfile:
...
USER vscode
COPY devcontainer.bashrc /home/vscode/.bashrc
...
and your devcontainer.bashrc
alias ll="ls -l"
alias la="ls -a"
and avoid writing long commands in your "postCreateCommand" which is harder to debug/modify as it gets long
Edit: in reply to comment: If you don't want to create a Dockerfile and are using the pure devcontainer.json approach, you could do:
{
"postCreateCommand": "cp ${containerWorkspaceFolder}/devcontainer.bashrc /home/vscode/.bashrc
}
New environment configuration file: /etc/devcontainer
docker - How to start a devcontainer in vscode with bash instead of sh? - Stack Overflow
Loading bash profile into container
How to get VS Code devcontainer to execute bash command? - Stack Overflow
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
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