Home > Net >  How to use powershell to interact with docker container ("\r" command not found)
How to use powershell to interact with docker container ("\r" command not found)

Time:12-02

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: $'ls\r': command not found

I assume this is because newlines in windows (\r\n) 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).

CodePudding user response:

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.

CodePudding user response:

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
  • Related