0

(Was asked here, was closed because "not about programming or software development.")

Situation: I have a Docker Compose setup with multiple containers from different images. I have Docker Desktop to access the terminals via the "Exec" tab. I run terminal scripts in some containers.

Problem: Some terminals don't allow arrow navigation. When I press Key-Up, I receive ^[[A.

Temporary solution: According to https://stackoverflow.com/questions/69179458/how-to-permanently-enable-arrow-keys-for-docker-desktop-cli I can run /bin/bash before doing anything else. But this works only as long as the container lives.

Question: How to configure a container in the Docker Compose file, so that Docker Desktop's "Exec" Tab runs by default with /bin/bash?

  • I tried multiple things with command and post_start, but nothing worked. Either the container failed to start, or the Terminal was not in bash mode.
  • I don't want to build a custom image just for this behavior.
  • I use Windows and WSL 2.

To reproduce:

services: arrow-working: image: php:8.1.11-fpm-alpine arrow-not-working: image: postgres:15.2 # what to add here, to automatically enable bash in Docker Desktop Exec? environment: POSTGRES_PASSWORD: foo 
1
  • As stated on SO the feature you are asking for is not implemented as of September 2025. One workaround is to create a symlink between /bin/sh and /bin/bash. You can also install rlwrap and run rlwrap sh, which provides readline and arrow key support. Either way, this requires building a new image. Now, what you are asking for has been requested multiple times, so it may be added in the near future. In the meantime, you can always open an issue or submit your own PR to the project. Commented Sep 9 at 14:01

1 Answer 1

0

Here What you can use to avoid writing bash or sh oring /bin/sh

Step1: create docker-compose.yml file I take this from you reference services: arrow-not-working: image: postgres:15.2 environment: POSTGRES_PASSWORD: foo Step 2: Run docker-compose.yml Right now you have to write docker exec -it <container_id> bash Step 3: after this open yout bash script using nano ~/.bashrc Step 4: add this bash command dexec() { local container="$1" if docker exec "$container" which bash >/dev/null 2>&1; then docker exec -it "$container" bash else docker exec -it "$container" sh fi }
Here I created a function name dexec() check condition(container_id or name) It search from pool of conatiner and automatical put into that particular bash container or if not present go for sh. Now Save it Step 5: source ~./bashrc #reload the script. Step 6: After that you can use dexec <conatainer_id> any not for docker-compose.yml  Start Docker Image

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.