How to fix ctrl + c inside docker container

If I connect to the docker container

$> docker exec -it my_container zsh

and inside of him I want to kill something that I started with ctrl+c. I noticed that it ends forever. I searched googled and it seems to ctrl+cwork a little different than you expected. My question is, how can I fix it ctrl+cinside the container?

+17
source share
4 answers

, Ctrl-C , , . ID 1 , , , . , , , . here. - , Ctrl-C.

docker 0.6.5, -t , pseudo-TTY. Control-C, , .

-t -i, Control-C . -i with -t Control-P Control-Q .

1:

$ ID=$(sudo docker run -t -d ubuntu /usr/bin/top -b)
$ sudo docker attach $ID
Control-P Control-Q
$ sudo docker ps

.

2:

$ ID=$(sudo docker run -t -i -d ubuntu /usr/bin/top -b)
$ sudo docker attach $ID
Control-C
$ sudo docker ps

( ). Control-P Control-Q Control-C 2- , .

bash docker-entrypoint.sh, ctrl-c. bash : https://rimuhosting.com/knowledgebase/linux/misc/trapping-ctrl-c-in-bash

#!/bin/bash

# trap ctrl-c and call ctrl_c()
trap ctrl_c INT

function ctrl_c() {
        echo "** Trapped CTRL-C"
}

for i in 'seq 1 5'; do
    sleep 1
    echo -n "."
done
+20

Ctrl + \ Ctrl + C
, , . ( .)

+4

, mdbook ( Rust) Docker. mdbook -, Ctrl + C, .

$ docker -ti --rm -p 4321:4321 my-docker-image mdbook serve --hostname 0.0.0.0 --port 4321
2019-08-16 14:00:11 [INFO] (mdbook::book): Book building has started
2019-08-16 14:00:11 [INFO] (mdbook::book): Running the html backend
2019-08-16 14:00:11 [INFO] (mdbook::cmd::serve): Serving on: http://0.0.0.0:4321
2019-08-16 14:00:11 [INFO] (ws): Listening for new connections on 0.0.0.0:3001.
2019-08-16 14:00:11 [INFO] (mdbook::cmd::watch): Listening for changes...
^C^C

@NID, mdbook bash docker-entrypoint.sh, ( INT).

$ docker -ti --rm -p 4321:4321 my-docker-image docker-entrypoint.sh mdbook serve --hostname 0.0.0.0 --port 4321
2019-08-16 14:00:11 [INFO] (mdbook::book): Book building has started
2019-08-16 14:00:11 [INFO] (mdbook::book): Running the html backend
2019-08-16 14:00:11 [INFO] (mdbook::cmd::serve): Serving on: http://0.0.0.0:4321
2019-08-16 14:00:11 [INFO] (ws): Listening for new connections on 0.0.0.0:3001.
2019-08-16 14:00:11 [INFO] (mdbook::cmd::watch): Listening for changes...
^C $

docker-entrypoint.sh :

#!/bin/bash

$@
+2

ID :

$ docker ps

then type

$ docker stop 07a5ac282a81

( 07a5ac282a82 , )

0

Source: https://habr.com/ru/post/1663496/


All Articles