docker-compose exec -d (detached) doesn't return control of terminal
According to the documentation docker-compose exec -d should run in detached mode, but after running with -d the control of the terminal is not returned. Am I missing something?
It works for me.
You're missing the version of Compose you're using, the command you're running, and basically any other details that would allow me to attempt reproducing your issue.
docker-compose --version
docker-compose version 1.11.2, build dfed245
docker --version
Docker version 17.03.0-ce, build 60ccb22
The command is basically any.
docker-compose exec -d [service_name] bash hangs and doesn't return the terminal.
docker-compose exec -d [service_name] ls hangs and doesn't return the terminal.
For example I have a very simple service called mariadb. My yml looks like this
mariadb:
image: mariadb:latest
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: database
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
volumes:
- mariadb:/var/lib/mysql
Then I run docker-compose up -d mariadb
Then I run docker-compose exec -d mariadb bash and it just hangs and doesn't return the terminal. When I run without the -d option it takes me into the bash shell interactively.
Maybe a similar issue : let's suppose the following script "telnet_client.sh" into a container named "telnet-client" :
while true; do
if [ $# -eq 4 ]
then
TELNET_SERVER=$1
NAME=$2
PASSWORD=$3
COMMANDS=$4
eval '{ echo;
sleep 3;
echo $NAME ;
sleep 1;
echo $PASSWORD ;
sleep 1;
echo $COMMANDS ;
sleep 1; }' | telnet $TELNET_SERVER
else
echo "Not enough arguments ! "
fi
done;
If I call the following :
docker-compose exec -d telnet_client bash -c '/telnet_client.sh telnet_server jack jack ls'
The control in the terminal is not returned.
Otherwise , if I call this :
docker exec -d lab3_telnet_client_1 bash -c '/telnet_client.sh telnet_server jack jack ls'
the script is called correctly in background mode .
Docker version : Docker version 17.03.1-ce, build c6d412e
docker-compose version 1.11.2, build dfed245
On mac pro book , Sierra
A possible workaround could be
docker exec -d $(docker-compose ps -q service_name) command
@giper45
Does it work with docker-compose exec -T -d telnet_client bash -c '/telnet_client.sh telnet_server jack jack ls'?
By default, Compose allocates a TTY, while the Docker CLI doesn't, so the two commands you're using are not equivalent unless you add -T in the Compose case. This might be the reason for the discrepancies you're seeing.
@shin-
Unfortunately it doesn't work , I just try ... this is the definition of container in docker-compose yaml :
telnet_client:
image: '...debian_bot:latest'
stdin_open: true
tty: true
networks:
internal_network:
ipv4_address: 192.168.1.3
cap_add:
- NET_ADMIN
Maybe stdin_open and tty options could cause this ? Anyway, with docker exec command I resolved, let me know if I can give you further infos in order to discover if there is a problem !
Thanks, I was able to reproduce and identify the issue. This should be fixed by #4737