skip to Main Content

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

  1. Set the podman alias over docker names.
alias docker='podman'
alias docker-compose='podman-compose'
  1. Add a script on package.json to use the docker-compose.
"scripts": {
    "start": "docker-compose up --build",
    ...
  1. 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


  1. Chosen as BEST ANSWER

    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

    ...
    script-shell = null
    searchexclude = ""
    searchlimit = 20
    searchopts = ""
    searchstaleness = 900
    shell = "/bin/zsh"
    ...
    

    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


  2. 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.

    Login or Signup to reply.
  3. I got this working by:

    1. Adding alias docker='podman' to ~/.zshenv
    2. Running npm config set script-shell zsh

    See: https://github.com/npm/cli/issues/5153

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search