Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why docker container exits with code 0?

I am currently trying to create a Messenger Bot with Botkit framework !

Since I work on different computers I want to use docker to prevent any local configurations problems.

Unfortunately, I am new to botkit AND docker.

file structure

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

4 directories, 5 files

docker-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"

docker/botkit/Dockerfile

FROM node:8
RUN npm install botkit

docker/node/Dockerfile

FROM node:8
EXPOSE 8888

Steps to reproduce the error

When I run

docker-compose build

I've got

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 [email protected]: 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.

+ [email protected]
added 349 packages in 48.021s
Removing intermediate container d57d1ac5e112
 ---> 6530cdad7dfe
Successfully built 6530cdad7dfe
Successfully tagged nook_bot_botkit:latest

Then I do

docker-compose up

I get

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

If I ran

docker exec -ti nook_bot_app_1 bash

I get

Error response from daemon: Container a4c9724bc954c6bab19a5953c2fea315b95caf64f26c8ca0b036ca3f037fd398 is not running

logs

I ran

docker logs nook_bot_app_1

I get

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"
}

I don't understand how come docker doesn't find my package.json file since by running docker-compose build and up it does create the file. I suppose the exit code 0 issue come from here but I really don't understand why. Maybe I lack some basic understanding on how docker actually works.

I searched for other questions about exit code 0 but none of the answers was helpful.

In the end I just want to run bash on my app container in order to start building my bot.

Thanks for any further help !

like image 772
Gane D. Geoffrey Avatar asked Apr 27 '18 13:04

Gane D. Geoffrey


People also ask

Why does my docker container keep exiting?

This happens if you run a foreground container (using docker run ), and then press Ctrl+C when the program is running. When this happens, the program will stop, and the container will exit. The container has been stopped using docker stop : You can manually stop a container using the docker stop command.

What causes a container to exit with code 137?

Exit code 137 is triggered when a pod or a container within your Kubernetes environment exceeds the amount of memory that they're assigned. Typically, this exit code is accompanied by or simply known as OOMKilled.

What does IP 0.0 0.0 mean docker?

0.0.0.0 means all available interfaces which does include localhost but also others e.g. 192.168.0.123.

What is the exit code of the stopped container?

Exit Code 0: Purposely Stopped. Exit Code 0 is triggered by developers when they purposely stop their container after a task completes. Technically, Exit Code 0 means that the foreground process is not attached to a specific container.


Video Answer


2 Answers

Try tty: true:

node:

build: ./docker/node

volumes_from:
    - "app"
    tty: true

This worked for me with PHP and MySQL container.

like image 50
Eduardo Gonçalves Avatar answered Sep 21 '22 22:09

Eduardo Gonçalves


You have to understand that Docker, before building your image, needs to prepare a context in which it will build your files. You have your package.json, but you never really added it to your image context.

You should read about COPY <src> <dest> from Dockerfile docs.

The COPY instruction will copy new files from <src> and add them to the > container's filesystem at path <dest>

like image 20
Rodrigo Siqueira Avatar answered Sep 20 '22 22:09

Rodrigo Siqueira