Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

309
Views
Why does the following docker-compose execution exit without waiting for user input?

When I run the following simple Node.js code (index.js) using Docker, the code executes as expected - waiting for user input. But when I run the same code using Docker-Compose, Node.js exits before waiting for user input.

I've been able to run the Node application using the Dockerfile, but not Docker-Compose

Here is the index.js file that I'm able to run in the Dockerfile (but not Docker-Compose):

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

readline.question(`What's your name? `, (name) => {
  console.log(`Hi ${name}!`)
  readline.close()
});

And the Dockerfile I used:

FROM node:12.2

ENV NODE_ENV=development
ENV NPM_CONFIG_LOGLEVEL warn

WORKDIR /app
COPY package*.json /app/
RUN npm install && npm cache clean --force

WORKDIR /app/src
CMD ["node", "index.js"]


As with the Dockerfile experience:

```shell
$ docker build -t commandline .
...
$ docker run -it --rm -v $(pwd)/src:/app/src commandline
What's your name? Scott
Hi Scott!

I expected the Docker-Compose version to execute the same way, but it exits the Node and Docker process before the user has an opportunity to respond:

$ docker-compose up
Creating mega_node_1 ... done
Attaching to mega_node_1
node_1  | What's your name? mega_node_1 exited with code 0
$ 
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!