Search code examples
bashdockerdocker-compose

Docker closes bash on error/failed command


I have a docker file that ends with CMD ["sleep", "infinity"]. I am able to start it using docker compose <service> up -d and attach to a terminal session using docker compose <service> bash.

But the bash session closes if there are any errors/failed commands (eg. misspelled commands), at which point I have to attach again and pick up where I left off. Is there a way to keep bash alive even when a command fails? I tried using docker run -it .... but that had the same issue


Solution

  • You can use set +e bash option to continue next commands even if there are some errors

    So, for example, you can use the command below to start new bash session:

    docker-compose <service> exec -it <service> bash -c "set +e; exec bash"