Home > Enterprise >  Why does "docker-compose up" exit but "docker-compse run" enters into bash shell
Why does "docker-compose up" exit but "docker-compse run" enters into bash shell

Time:11-08

Dockerfile

FROM get some base image

ENV ProjectDir /workarea/svc

RUN mkdir -p $ProjectDir

WORKDIR $ProjectDir

docker-compose.yaml

version: "3.7"

services:
    svc:
        build:
            context: .
            dockerfile: Dockerfile
        volumes:
            - .:/workarea/svc
        command: ["/opt/bb/bin/bash"]

When I run docker-compose up it exits immediately

r@PW02R9F3:$ docker-compose up
Creating svc_dev_1 ... done
Attaching svc_dev_1
svc_dev_1 exited with code 0

But when I run "docker-compose run --rm dev" I am able to get into bash as specified in the command session of my docker-compose.yaml file

r@PW02R9F3:$ docker-compose run --rm dev
Creating svc_dev_run ... done
[root@ad5d3d7107b4 svc]#

Why is this happening? Isnt "docker-compose up" running my command "/opt/bb/bin/bash" in the docker-compose.yaml file?

CodePudding user response:

I believe this is because docker compose run spawns a container in interactive mode (unless specified otherwise) by default. docker compose up does not.

That is of importance because when running bash in a container that is not in interactive mode, it just dies immediately with status code 0 not because there's an error, but because there's no input for bash (and won't be).

It's like running docker run ubuntu and docker run -it ubuntu. The latter will keep STDIN open, "listening" for commands if you will.

  • Related