skip to Main Content

Any commands hang terminal inside docker container.

I login in container with docker exec -t php-zts /bin/bash
And then print any elementary command (date, ls, cd /, etc.)

Command hang

When I press ctrl+c I going back to host machine.
But, if I run any command without container – it’s work normally

docker exec -t php-zts date
Wed Jan 26 00:04:38 UTC 2022

tty is enabled in docker-compose.yml
docker system prune and all cleanups can not help me.

I can’t identify the problem and smashed my brain. Please help 🙁

2

Answers


  1. The solution is to use the flag -i/--interactive with docker run. Here is a relevant section of the documentation:

    --interactive , -i Keep STDIN open even if not attached

    Login or Signup to reply.
  2. You can try to run your container using -i for interactive and -t for tty which will allow you to navigate and execute commands inside the container

    docker run -it --rm  alpine
    

    In the other hand you can run the container with docker run then execute commands inside that container like so:

    • tail -f /dev/null will keep your container running.
    • -d will run the command in the background.
    docker run --rm -d --name container1 alpine tail -f /dev/null 
    or
    docker run --rm -itd --name container1 alpine sh # You can use -id or -td or -itd
    
    • This will allow you to run commands from inside the container.
    • you can choose sh, bash, or any other shell you prefer.
    docker exec -it container1 alpine sh
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search