简体   繁体   English

Docker compose继续退出MERN堆栈的Web服务,状态为1

[英]Docker compose keeps on exiting the web service of MERN stack with status 1

Docker Compose question : My directory looks like this : Docker撰写问题:我的目录如下所示:

total 720
drwxr-xr-x 2 anix anix   4096 Apr 14 13:40 bin
drwxr-xr-x 2 anix anix   4096 Apr 14 06:21 config
-rw-r--r-- 1 anix anix    788 Apr 14 13:38 docker-compose.yml
-rw-r--r-- 1 anix anix    361 Apr 14 13:39 dockerfile
-rw-r--r-- 1 anix anix    651 Apr  6 16:35 ecosystem.config.js
-rw-r--r-- 1 anix anix   2661 Apr  6 16:35 package.json
-rw-r--r-- 1 anix anix 689928 Apr  6 16:28 package-lock.json
drwxr-xr-x 4 anix anix   4096 Apr  4 09:30 public
-rw-r--r-- 1 anix anix    832 Apr  7 01:51 README.md
drwxr-xr-x 5 anix anix   4096 Apr  4 02:36 src
drwxr-xr-x 2 anix anix   4096 Apr  4 04:24 __test__
-rw-r--r-- 1 anix anix   2887 Apr  6 14:16 webpack.config.js

here is my docker-compose.yml file : 这是我的docker-compose.yml文件:

version: '3.4'
services:
        web:
                build:
                        context: ./
                        dockerfile: dockerfile
                depends_on:
                        - db
                ports:
                        - "8000:5000"
                volumes:
                        - .:/usr/src/app
                environment:
                        NODE_ENV: development
                        MONGO_URL: mongodb://db:27017/test

                stdin_open: true
                tty: true
        db:
                image: mongo:latest
                restart : always
                volumes:
                        - dbdata:/data/db
                ports:
                        - "27017:27017"
volumes:
        dbdata:


And here is the dockerfile : 这是dockerfile

FROM node:alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
EXPOSE 5000

ENV NODE_ENV development
COPY package.json package-lock.json ./

RUN npm install

COPY ./webpack.config.js ./
COPY .babelrc ./
COPY .eslintrc.json ./
COPY public ./public
COPY config ./config
COPY src ./src
COPY bin ./bin
COPY __test__ ./__test__



CMD ["npm","server:dev"]
RUN ls

This Is a MERN stack project and the docker-compose build is working fine but when I am doing docker-compose up getting some really weird error like this in the web service of the compose : 这是一个MERN堆栈项目和docker-compose build工作正常,但是当我做docker-compose up ,在compose的web服务中得到一些非常奇怪的错误:


db_1   | 2019-04-14T16:33:52.828+0000 I NETWORK  [initandlisten] waiting for connections on port 27017
db_1   | 2019-04-14T17:18:41.711+0000 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
db_1   | 2019-04-14T17:18:41.845+0000 I CONTROL  [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=3d58dc5ae58d
db_1   | 2019-04-14T17:18:41.845+0000 I CONTROL  [initandlisten] db version v4.0.9
db_1   | 2019-04-14T17:18:41.845+0000 I CONTROL  [initandlisten] git version: fc525e2d9b0e4bceff5c2201457e564362909765
db_1   | 2019-04-14T17:18:41.845+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
db_1   | 2019-04-14T17:18:41.845+0000 I CONTROL  [initandlisten] allocator: tcmalloc
db_1   | 2019-04-14T17:18:41.845+0000 I CONTROL  [initandlisten] modules: none
db_1   | 2019-04-14T17:18:41.845+0000 I CONTROL  [initandlisten] build environment:
db_1   | 2019-04-14T17:18:41.845+0000 I CONTROL  [initandlisten]     distmod: ubuntu1604
db_1   | 2019-04-14T17:18:41.845+0000 I CONTROL  [initandlisten]     distarch: x86_64
db_1   | 2019-04-14T17:18:41.845+0000 I CONTROL  [initandlisten]     target_arch: x86_64
db_1   | 2019-04-14T17:18:41.845+0000 I CONTROL  [initandlisten] options: { net: { bindIpAll: true } }
db_1   | 2019-04-14T17:18:41.877+0000 W STORAGE  [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
db_1   | 2019-04-14T17:18:41.892+0000 I STORAGE  [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'

db_1   | 2019-04-14T17:18:45.437+0000 I NETWORK  [initandlisten] waiting for connections on port 27017
db_1   | 2019-04-14T17:18:46.075+0000 I FTDC     [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK

samplemern_web_1 exited with code 1

And after this, the web container is getting stopped and only the MongoDB container is running and when I am executing the MongoDB container in -it interactive mode and doing ls there inside the /usr/src/ the whole directory is coming as empty. 在此之后,Web容器停止运行,只有MongoDB容器正在运行,当我在-it交互模式下执行MongoDB容器并在/usr/src/执行ls ,整个目录将变为空。

when I am executing the MongoDB container in -it interactive mode and doing ls there inside the /usr/src/ the whole directory is coming as empty. 当我在-it交互模式下执行MongoDB容器并在/ usr / src /中执行ls时,整个目录将变为空。

that exactly what should be, because /usr/src/app is the path you have defined for your app in the app service, not in the mongo container. 究竟应该是什么,因为/ usr / src / app是您在应用服务中为应用定义的路径,而不是在mongo容器中。

your problem is that since volume is not removed when you stop the containers, it seems to become 'dirty' from previous runs. 你的问题是,因为当你停止容器时没有删除卷,它似乎从以前的运行变得“脏”。

try running docker volume rm dbdata before you docker-compose up . 尝试在docker volume rm dbdata docker-compose up之前运行docker volume rm dbdata

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM