lazydocker icon indicating copy to clipboard operation
lazydocker copied to clipboard

Custom command passing a string literal

Open pythoninthegrass opened this issue 3 years ago • 8 comments
trafficstars

Describe the bug Running an ad hoc docker run command in the terminal works. Passing the same command to lazydocker as either a scalar (folded/literal) or inline fails.

To Reproduce Steps to reproduce the behavior:

  1. Create a custom command in config.yml
    - name: run-meetup
      attach: true
      command: >
        docker run -it --name meetup_bot
        -p 80:3000
        -e PORT="3000"
        -v "$(pwd)":/home/appuser/app
        --env-file .env
        meetup_bot
        bash
    
    or
    - name: run-meetup
      attach: true
      command: 'docker run -it --name meetup_bot -p 80:3000 -e PORT="3000" -v "$(pwd)":/home/appuser/app --env-file .env meetup_bot bash'
    
  2. Open lazydocker
  3. Run the command
  4. Raises error:
    + docker run -it --name meetup_bot -p 80:3000 -e PORT=3000 -v $(pwd):/home/appuser/app --env-file .env meetup_bot bash
    
    docker: Error response from daemon: create $(pwd): "$(pwd)" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
    See 'docker run --help'.
    

Expected behaviour It should interpolate/expand the pwd command or $PWD built-in variable in the command. Only able to hard-code the absolute path to work around the issue. Less than ideal, of course.

Screenshots N/A

Desktop (please complete the following information):

  • OS: macOS 12.4 (21F79)
  • Lazydocker Version: v0.18.1
  • The last commit id if you built project from sources: N/A

Additional context Using the new docker mount syntax got the same results.

pythoninthegrass avatar Jun 13 '22 01:06 pythoninthegrass

$(pwd) have to run in the shell, but lazydocker seems like run command directly. I think this is not bug, but run commands through shell will be more convenient I think.

skanehira avatar Jul 04 '22 14:07 skanehira

What would you suggest the workflow should be if this isn't a bug @skanehira?

pythoninthegrass avatar Jul 07 '22 03:07 pythoninthegrass

I agree, we ought to run all custom commands in a shell so that things like $(pwd) can be evaluated. We do that currently with lazygit

jesseduffield avatar Oct 08 '22 20:10 jesseduffield

The place we could update is here. In lazygit we have a NewShell function which takes a command and wraps it in a shell invocation (see here) so we can copy that approach in lazydocker

jesseduffield avatar Oct 08 '22 20:10 jesseduffield

I'll tackle this one.

gusandrioli avatar Oct 15 '22 17:10 gusandrioli

go ahead @gusandrioli :)

jesseduffield avatar Oct 15 '22 17:10 jesseduffield

Appreciate the follow-up! 🙏

pythoninthegrass avatar Oct 15 '22 17:10 pythoninthegrass

@pythoninthegrass PR was merged :)

gusandrioli avatar Dec 13 '22 19:12 gusandrioli