My Dockerfile
FROM node:lts-alpine
RUN echo echo Hi Bob >> /etc/profile
Run
docker build -t node5 .
docker run -it --rm node5 sh
I'm expecting to see "Hi Bob" output in the terminal. It's not there.
How do on this distro do I run a command automatically when opening a terminal?
UPDATE 1
Tried this too. No joy.
RUN echo echo HI Bob >> /root/.profile
UPDATE 2
Following Joe Perri's link I find that this works using
docker run -it --rm node5 sh -l
So it just requires the terminal to be configured as a login console to work.
However opening the same container as a dev container in VsCode with the following .devcontainer.json config still fails.
{
"build": {
"dockerfile": "./Dockerfile"
},
"userEnvProbe": "loginShell"
}
My motivation is that I'm trying to construct a project such that I can spin up a stack of services in Docker containers using docker-compose up
but then also connect to any of those containers using VsCode.
This mostly works. The only wrinkle is that many of these service containers will be running dev processes internally e.g. nodemon
, ng serve
etc, and while VsCode connects to the container ok it doesn't connect its terminal to the instance already running the dev process.
I'm trying to wire this up by launching the original dev process in a tmux session, and then automatically running a command to reconnect to that tmux session when VsCode connects to the container. This works great if I reconnect to the session manually, the only issue is that when VsCode connects to the container I can't get it to run the command to reconnect the session automatically (or any other command for that matter).