skip to Main Content

The docker compose yml file below keeps the container open after I run docker compose up -d but command: bash does not get executed:

version: "3.8"
services:
  service:
    container_name: pw-cont
    image: mcr.microsoft.com/playwright:v1.30.0-focal
    stdin_open: true          # -i
    tty: true                 # -t
    network_mode: host        # --network host
    volumes:                  # Ensures that updates in local/container are in sync
      - $PWD:/playwright/
    working_dir: /playwright
    command: bash

After I spin the container up, I wanted to visit Docker Desktop > Running container’s terminal.

Expectation: Since the file has command: bash, I expect that in docker desktop, when I go to the running container’s terminal, it will show root@docker-desktop:/playwright#.

Actual: Container’s terminal in docker desktop is showing #, still need to type bash to see root@docker-desktop:/playwright#.

Can the yml file be updated so that bash gets auto executed when spinning up the container?

2

Answers


  1. docker compose doesn’t provide that sort of interactive connection. Your docker-compose.yaml file is fine; once your container is running you can attach to it using docker attach pw-cont to access stdin/stdout for the container.

    $ docker compose up -d
    [+] Running 1/1
     ⠿ Container pw-cont  Started                                                                       0.1s
    $ docker attach pw-cont
    root@rocket:/playwright#
    root@rocket:/playwright#
    
    Login or Signup to reply.
  2. I’m not sure what you are trying to achieve, but using the run command

    docker-compose run service
    

    gives me the prompt you expect.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search