我是这方面的绝对初学者。
我需要运行两个容器,以及两个独立的应用程序。 其中一个应该运行一个脚本(它运行 npm start 而不是其他的),但这可能是不可能的?
Dockerfile
FROM node:14.16.0-buster
RUN apt-get update && apt-get install -y libsecret-1-dev groff less bash-completion && rm -rf /var/lib/apt/lists/*
ENV npm_config_user root
COPY startscript.sh /usr/local/bin
RUN chmod +x /usr/local/bin/startscript.sh
ENTRYPOINT []
还有 docker-compose.yml
version: '3'
services:
first-container:
build:
context: .
ports:
- '8080:8080' # node web interface
env_file: .env
command: bash -c "/usr/local/bin/startscript.sh"
second-container:
build:
context: .
ports:
- '8181:8181' # node main app web interface
# volumes:
volumes:
node-modules: # persist local node_modules
我可以运行容器,但脚本不会自动运行。 建议?
谢谢
答案 0 :(得分:0)
只需运行 ENTRYPOINT ["npm","start"]
而您想运行 2 个命令只需创建一个脚本文件 script.sh
#!/bin/bash
npm start &
# Other command here
然后ENTRYPOINT ["/script.sh"]