I’m migrating Docker to Podman and the alias not is working when invoked by npm.
I added on my env alias:
alias docker='podman'
alias docker-compose='podman-compose'
To test the alias I ran docker-compose up --build
and works correctly using podman-compose, like expected.
I have on my package.json:
"scripts": {
"start": "docker-compose up --build",
...
When a I ran npm run start, this is the output:
❯ npm run start
> [email protected] start
> docker-compose up --build
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I did one more test, change the docker-compose to podman-compose on package.json file and works too.
Expected Behavior
Recognize the env alias. Like happen when I run the command direct on the terminal.
Steps To Reproduce
- Set the podman alias over docker names.
alias docker='podman'
alias docker-compose='podman-compose'
- Add a script on package.json to use the docker-compose.
"scripts": {
"start": "docker-compose up --build",
...
- Run the npm script.
npm run start
Environment
- npm: 8.13.2
- Node.js: v14.19.3
- OS Name: macOS 12.4 (Monterey)
- System Model Name: Macbook Pro M1
- npm config:
❯ npm config ls
; node bin location = /Users/XPTO/.nvm/versions/node/v14.19.3/bin/node
; node version = v14.19.3
; npm local prefix = /Users/XPTO
; npm version = 8.13.2
; cwd = /Users/XPTO
; HOME = /Users/XPTO
; Run `npm config ls -l` to show all defaults.
3
Answers
Here is the solution.
Check if you have your script-shell set to your terminal.
To check just use the command
npm config ls -l
If your “script-shell“ value is null, set this value to your default terminal using this command
npm config set script-shell zsh
(the zsh is macOS Catalina default terminal) should do the trick here if you don't mind changing your shell for every project. if you'd rather be more specific, you can add--location=project
to that command and a.npmrc
file will be created in your project and the setting will only apply to that one project.Here the source: https://github.com/npm/cli/issues/5153#issue-1302253170
Maybe npm runs under different user where the aliases don’t exist. Check it by adding id command to your start script.
Another guess: run it in a new terminal window to reload user environment.
I got this working by:
alias docker='podman'
to~/.zshenv
npm config set script-shell zsh
See: https://github.com/npm/cli/issues/5153