1

I try to run a node.js container with docker. Unfortunately, the container always stop and i can't get any log to understand why. When i restart the container, it instantly stops and i can't connect into it through the terminal.

About my docker-compose.yml:

version: '2'
services:
    node:
        build: .
        container_name: node.cs
        restart: unless-stopped
        ports:
            - 3030:3000
        volumes:
            # app
            - ./app:/app

About my Dockerfile:

FROM node:10.9.0-alpine

# Create app directory
RUN mkdir /app
WORKDIR /app

# Set environment to "development" by default
ENV NODE_ENV development

# make port available outside of the image
EXPOSE 3000

As i suspect a permission conflict, here is my local working folder content:

drwxrwxr-x  2 myuser myuser 4096 août  30 00:07 app
-rwxr-xr-x  1 myuser myuser  791 août  30 06:41 docker-compose.yml
-rw-rw-r--  1 myuser myuser  412 août  30 06:40 Dockerfile
-rw-rw-r--  1 myuser myuser   98 août  28 22:43 .dockerignore

Any help to understand what is wrong with my code is welcomed. Thank you in advanced. jB

2
  • 1
    Can you please add a bit more info? Your Dockerfile does not have a CMD, I assume you're trying to run an Express server or similar, but your container runs the default CMD of the node image CMD [ "node" ]. What are you launching exactly? I also do not see if you npm install it's not in the Dockerfile. Are node_module in your app directory? Did you try to use docker-compose logs to see the logs? Commented Aug 30, 2018 at 6:04
  • Thank you for the answer. Actually i don't have any app ready with server.js ir package.json. I juste would like ti get the server to make some tests with the terminal. I will check the logs. Commented Aug 31, 2018 at 21:25

2 Answers 2

0

Dockerfile

FROM node:10.9.0-alpine
WORKDIR /app
ADD . /app
RUN npm install
RUN npm install -g nodemon
# Set environment to "development" by default
ENV NODE_ENV=development

# Create app directory
# make port available outside of the image
CMD ["nodemon", "-L"]
EXPOSE 3000

docker-compose.yml

version: '3'
services:
   application:
   build: .
   container_name: whatever_name_you_choice
   restart: always
   ports:
   - "3000:3000"
   volumes:
   - .:/app
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for the answer. It doesn't seem to work (nodemon doesn't solve anything) but i will investigate deeply.
Hello, with your files i get this error: ERROR: In file './docker-compose.yml', service 'volumes' must be a mapping not an array.. After some change, the build seems to work but the container remains stopped. In docker-compose logs, i get: Attaching to my.container node.cours | /bin/sh: [nodemon,: not found. I hope it helps.
That only promblem of format when we copy paste. I test that file and that work normal... You may edited your yml format, I run this files to test them for you. The problem is i use single qoute instead dobble edit CMD like this CMD ["nodemon", "-L"]. My bad, I wrote that file and does't test them yet... Now it work..
I edited my file. You can copy them and try again... I so sorry
0

Run the command:

docker compose run server npm install jest

And it will work. Or else, your container node might a little bit old version, then just:

docker image pull node

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.