繁体   English   中英

为什么docker container退出代码为0?

[英]why docker container exits with code 0?

我目前正在尝试使用Botkit框架创建一个Messenger Bot!

由于我在不同的计算机上工作,我想使用docker来防止任何本地配置问题。

不幸的是,我是botkit和docker的新手。

文件结构

bot
├── README.md
├── docker
│   ├── botkit
│   │   └── Dockerfile
│   └── node
│       └── Dockerfile
├── docker-compose.yml
├── node_modules
└── package.json

4 directories, 5 files

泊坞窗,compose.yml

version: "2"
services:
    node:
        build: ./docker/node
        volumes_from:
            - "app"
    botkit:
        build: ./docker/botkit
        links:
            - "node"
        volumes_from:
            - "app"
    app:
        image: "node:8"
        working_dir: /home/nook_bot
        environment:
            - NODE_ENV=production
        volumes:
            - .:/home/nook_bot
            - /home/nook_bot/node_modules
        command: "npm init --yes && npm start"

搬运工/ botkit / Dockerfile

FROM node:8
RUN npm install botkit

搬运工/节点/ Dockerfile

FROM node:8
EXPOSE 8888

重现错误的步骤

我跑的时候

docker-compose build

我有

app uses an image, skipping
Building node
Step 1/2 : FROM node:8
8: Pulling from library/node
f2b6b4884fc8: Pull complete
4fb899b4df21: Pull complete
74eaa8be7221: Pull complete
2d6e98fe4040: Pull complete
452c06dec5fa: Pull complete
7b3c215894de: Pull complete
094529398b79: Pull complete
449fe646e95b: Pull complete
Digest: sha256:26e4c77f9f797c3993780943239fa79419f011dd93ae4e0097089e2145aeaa24
Status: Downloaded newer image for node:8
 ---> 4635bc7d130c
Step 2/2 : EXPOSE 8888
 ---> Running in 3a5be5fca913
Removing intermediate container 3a5be5fca913
 ---> 87cf54fd2907
Successfully built 87cf54fd2907
Successfully tagged nook_bot_node:latest
Building botkit
Step 1/2 : FROM node:8
 ---> 4635bc7d130c
Step 2/2 : RUN npm install botkit
 ---> Running in d57d1ac5e112
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
npm WARN saveError ENOENT: no such file or directory, open '/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/package.json'
npm WARN !invalid#1 No description
npm WARN !invalid#1 No repository field.
npm WARN !invalid#1 No README data
npm WARN !invalid#1 No license field.

+ botkit@0.6.13
added 349 packages in 48.021s
Removing intermediate container d57d1ac5e112
 ---> 6530cdad7dfe
Successfully built 6530cdad7dfe
Successfully tagged nook_bot_botkit:latest

然后我做

docker-compose up

我明白了

Creating nook_bot_app_1 ... done
Creating nook_bot_node_1 ... done
Creating nook_bot_botkit_1 ... done
Attaching to nook_bot_app_1, nook_bot_node_1, nook_bot_botkit_1
app_1     | Wrote to /home/nook_bot/package.json:
app_1     |
app_1     | {
app_1     |   "name": "nook_bot",
app_1     |   "version": "1.0.0",
app_1     |   "description": "",
app_1     |   "main": "index.js",
app_1     |   "dependencies": {},
app_1     |   "devDependencies": {},
app_1     |   "scripts": {
app_1     |     "test": "echo \"Error: no test specified\" && exit 1"
app_1     |   },
app_1     |   "repository": {
app_1     |     "type": "git",
app_1     |     "url": "git+https://github.com/Geoffrey42/nook_bot.git"
app_1     |   },
app_1     |   "keywords": [],
app_1     |   "author": "",
app_1     |   "license": "ISC",
app_1     |   "bugs": {
app_1     |     "url": "https://github.com/Geoffrey42/nook_bot/issues"
app_1     |   },
app_1     |   "homepage": "https://github.com/Geoffrey42/nook_bot#readme"
app_1     | }
app_1     |
app_1     |
nook_bot_node_1 exited with code 0
nook_bot_app_1 exited with code 0
nook_bot_botkit_1 exited with code 0

如果我跑了

docker exec -ti nook_bot_app_1 bash

我明白了

Error response from daemon: Container a4c9724bc954c6bab19a5953c2fea315b95caf64f26c8ca0b036ca3f037fd398 is not running

日志

我跑了

docker logs nook_bot_app_1

我明白了

Wrote to /home/nook_bot/package.json:

{
  "name": "nook_bot",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {},
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/Geoffrey42/nook_bot.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/Geoffrey42/nook_bot/issues"
  },
  "homepage": "https://github.com/Geoffrey42/nook_bot#readme"
}

我不明白为什么docker找不到我的package.json文件,因为通过运行docker-compose build而它确实创建了该文件。 我想退出代码0问题来自这里,但我真的不明白为什么。 也许我对docker的实际工作方式缺乏一些基本的了解。

我搜索了关于退出代码0的其他问题,但没有一个答案是有帮助的。

最后我只想在我的app容器上运行bash,以便开始构建我的机器人。

感谢您的进一步帮助!

您必须了解Docker在构建映像之前需要准备一个用于构建文件的上下文。 你有你的package.json,但你从未真正将它添加到你的图像上下文中。

您应该从Dockerfile文档中了解COPY <src> <dest>

COPY指令将从<src>复制新文件,并将它们添加到路径<dest>的>容器的文件系统中

尝试tty: true

节点:

 build: ./docker/node volumes_from: - "app" tty: true 

这适用于PHP和MySQL容器。

暂无
暂无

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

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