3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

node.jsをdocker-composeで動かしたら、Error: Cannot find module '/bash'になる

Posted at

プログラミングを覚えて丁度1年くらいの未熟エンジニアがdeockerでnode.jsの環境構築をしてつまづいた話です。

  • Dockerfile
FROM node:14.5.0-alpine3.12

WORKDIR /app
COPY . /app
RUN npm install
  • docker-compose.yml
version: '3'

services:
  app:
    build: .
    ports:
      - 3000:3000
    tty: true
    volumes:
      - .:/app
    command: bash -c "node index.js"
    depends_on:
      - db

  db:
    image: postgres:12.2
    ports:
      - "5432:5432"
    environment:
      - "POSTGRES_USER=hogehoge"
      - "POSTGRES_PASSWORD=hogehoge"
      - "POSTGRES_DB=hogehoge"

これを実行すると

Error: Cannot find module '/app/bash'

って言われます。

結論

alpineにbashは無いそうです。。
alpineは軽量で良いと言われ、使っていました。
ちゃんと調べないとダメですね。。

command: ash -c "node index.js"

docker-compose.ymlのcommandのところをbash => ashに変えたらOKでした

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?