Symptoms:
docker-compose run mongo
, Mongo starts finedocker-compose run iotmap
or docker-compose up
only node starts, not the Mongo container plus2a) docker-compose ps
shows nothing and docker ps
shows
e968900e41cc 6e70e14f1339 "/bin/sh -c 'npm sta…" 3 minutes ago Up 2 minutes 3000/tcp priceless_hawking
2b) I get the following error
(node:25) UnhandledPromiseRejectionWarning: MongoTimeoutError: Server selection timed out after 30000 ms at Timeout._onTimeout (/usr/src/app/node_modules/mongodb/lib/core/sdam/server_selection.js:309:9) at listOnTimeout (internal/timers.js:537:17) at processTimers (internal/timers.js:481:7) (node:25) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode ). (rejection id: 1) (node:25) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. ERROR: Aborting.
docker-compose.yml:
volumes:
mongodata:
services:
iotmap:
container_name: iotmap
build: .
restart: always
ports:
- "3000:3000"
links:
- mongo
depends_on:
- mongo
mongo:
container_name: mongo
image: mongo:latest
restart: always
ports:
- "27017:27017"
volumes:
- mongodata:/data/db
and Dockerfile:
FROM node:latest
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install --no-optional --no-shrinkwrap --no-package-lock
COPY . /usr/src/app
EXPOSE 3000
RUN npm start
and in app.js:
mongoose.connect( "mongodb://mongo:27017/iotmap", {useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex: true } );
将RUN npm start
更改为CMD [ "npm", "start" ]
一切都像魅力一样开始!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.