Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

310
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda