如何修改Docker Compose配置让command: bash自动生效
问题分析
你遇到的情况是:容器启动后虽运行了bash,但Docker Desktop进入终端时默认调用了镜像自带的sh shell(表现为仅显示#提示符),而非你期望的bash环境。
解决方案
方案1:使用登录模式启动bash
将command改为bash -l,登录模式的bash会加载完整的环境配置,同时确保进入终端时直接处于bash环境:
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 -l
方案2:指定默认SHELL环境变量
添加environment字段设置默认shell为bash,Docker Desktop进入终端时会自动使用该shell:
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 environment: - SHELL=/bin/bash command: bash
方案3:覆盖镜像默认entrypoint
将entrypoint设置为bash,强制容器启动后直接运行bash:
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 entrypoint: bash
内容的提问来源于stack exchange,提问作者nakakapagpabagabag
相关产品推荐
相关产品推荐

