我需要先克隆wait-for-it代码库并编辑wait-for-it.sh文件吗?
https://github.com/vishnubob/wait-for-it/blob/master/wait-for-it.sh
我想在客服连接并启动服务器后的5秒内使我的主文件开始运行。(或每当客服连接服务器正常工作时)。
我知道在Dockerfile中,我们需要添加这些命令(将文件复制到工作目录,并将shell脚本作为可执行文件运行)。
...
COPY wait-for-it.sh .
RUN chmod +x /wait-for-it.sh
...
这是我的当前 Docker-Compose 文件
version: '3'
services:
books:
build: './books'
container_name: "horus-books"
ports:
- "30043:30043"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
customers:
depends_on:
- books
build: './customers'
container_name: "horus-customers"
ports:
- "6000:6000"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
main:
depends_on:
- customers
build: './main'
container_name: "horus-main"
ports:
- "4555:4555"
command: ["./wait-for-it.sh", "customers:6000", "--", "node", "main.js"]
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
主要服务Dockerfile
FROM node:12.14.0
WORKDIR /usr/src/app
COPY package*.json ./
COPY . /usr/src/app
COPY wait-for-it.sh .
RUN chmod +x /wait-for-it.sh
RUN npm install
EXPOSE 4555
CMD ["node", "main.js"]
RUN
命令在构建阶段只执行一次,不会影响运行中的容器。您需要更改CMD
或ENTRYPOINT
。 - tadman