skip to Main Content

My OS is Windows. When creating a Docker container and interacting with it using Windows powershell:

docker create -i --name test_container debian
docker container start -i test_container

And running a command such as ls, then it gives the following error:

bash: line 2: $'lsr': command not found

I assume this is because newlines in windows (rn) are different than unix (n).

How can I use powershell interactively with Docker?

I’ve searched online for a solution on this, but only get results on converting files, not working with powershell directly. I’ve also looked through the settings of Docker to see if there’s an option on this, but am unable to find anything to change this behavior. Running docker start --help does not provide any special options for usage with powershell.

I specifically want to use powershell as I dislike cmd and the shell provided by Docker (the up/down keys don’t work as expected for example).

2

Answers


  1. Chosen as BEST ANSWER

    I only now realized that I should pass the pseudo-tty option (-t) when creating the container.

    The following runs without issue:

    docker create -it --name test_container debian 
    docker container start -i test_container
    

    The problem is thus solved.


  2. Run it as:

    docker run -it --name test_container debian /bin/bash
    

    Here the explaination of the flags:

    • i: execute interactively
    • t: allocate a pseudo-tty
    • /bin/bash: to run a bash terminal regardless what is specified in the image
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search