Exec /bin/bash in Docker Compose

Viewed 4003

I am trying to automate a docker-compose file. I want to do some preliminary tasks like updating source codes, building a library, and automatically run bash terminal on the container just by calling docker-compose up. Is there a way to do this?
I tried to do the following:

version: '3.3'
services:
  service1:
    ...
  service2:
    build:
      dockerfile: Dockerfile.hardware
      context: .
    container_name: container2
    network_mode: "host"
    privileged: true
    environment:
      - DISPLAY=unix$DISPLAY
      - MACHINE=${MACHINE}
    shm_size: 256M
    volumes:
      ...
    stop_signal: SIGINT
    working_dir: /home/user
    command: bash -c "./Arduino/libraries/build_arduino_lib.sh && exec /bin/bash"

But the process terminates without executing /bin/bash.

1 Answers

To get an interactive bash, you need to use run and specify a service :

docker-compose run service2
Related