【发布时间】:2020-03-12 01:29:37
【问题描述】:
我正在开发一个使用 docker 部署的 MEAN STACK 应用程序。 docker-compose.yml 文件包含两个服务,一个用于 Angular 和 express,另一个用于 mongoDB。
在 docker-compose.yml 文件中:
version: '2' # specify docker-compose version
# Define the services/containers to be run
services:
webapp: #name of the second service
build: ./ # specify the directory of the Dockerfile
volumes :
- ./dockerScripts:/temp/scripts
entrypoint:
- /temp/scripts/wait-for-service.sh
- 'localhost'
- '27018'
- 'npm run serve'
ports:
- "3000:3000" #specify ports forewarding
appdb: # name of the third service
image: mongo # specify image to build container from
command: mongod --port 27018
expose:
- 27018
ports:
- "27018:27018" # specify port forewarding
下面是dockerFile的内容:
FROM mhart/alpine-node:10
MAINTAINER https://hub.docker.com/u/mhart/
RUN apk update && \
apk add git && \
apk add --no-cache python build-base && \
apk add busybox-extras && \
apk --no-cache add procps
#RUN apk add --no-cache python build-base
RUN mkdir -p /usr/src/
WORKDIR /usr/src/
COPY package.json .
RUN npm install --production
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
在执行 webapp 命令之前,我需要检查 mongodb 是否在指定端口上启动。
为了实现这一点,我编写了一个如下的 shell 脚本文件:
set -e
host="$1"
port="$2"
svc="$3"
echo `Inspectingggggg ` $host $port
until `telnet $host $port`; do
# until `ps -ax`; do
>&2 echo "Service is unavailable - going to sleeping "
sleep 5
done
>&2 echo "Service is now up, will execute npm run " $svc
npm run $svc
**
我面临的问题是如何检查mongodb服务是否启动 在执行 webapp 服务之前?
**
使用 telnet 命令我总是收到以下错误:
telnet: can't connect to remote host (127.0.0.1): Connection refused
templatexapp_1 | Service is unavailable - going to sleeping
【问题讨论】:
标签: mongodb shell docker docker-compose telnet