Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I fail in step 10 Run the following command to start your application. #22054

Closed
1 task done
minhsu12113 opened this issue Feb 19, 2025 · 2 comments
Closed
1 task done
Labels

Comments

@minhsu12113
Copy link

Is this a docs issue?

  • My issue is about the documentation content or website

Type of issue

I can't find what I'm looking for

Description

My Docker File

ARG NODE_VERSION=22.13.1
FROM node:${NODE_VERSION}-alpine
ENV NODE_ENV production 
WORKDIR /usr/src/app

RUN --mount=type=bind,source=package.json,target=package.json \
    --mount=type=bind,source=package-lock.json,target=package-lock.json \
    --mount=type=cache,target=/root/.npm \
    npm ci --omit=dev

USER node
EXPOSE 3000
CMD node src/index.js

My Compose File

services:
  server:
    build:
      context: .
    environment:
      NODE_ENV: production
      POSTGRES_HOST: db
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD_FILE: /run/secrets/db-password
      POSTGRES_DB: example
    ports:
      - 3000:3000 
    depends_on:
      db:
        condition: service_healthy
    secrets:
      - db-password
  db:
    image: postgres
    restart: always
    user: postgres
    secrets:
      - db-password
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=example
      - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
    expose:
      - 5432
    healthcheck:
      test: ["CMD", "pg_isready"]
      interval: 10s
      timeout: 5s
      retries: 5
volumes:
  db-data:
secrets:
  db-password:
    file: db/password.txt

My Project Struct

Image

When I run command docker compose up --build I get error as the below, I felt something wrong when docker try to mount or read something from db directory but how to fix it?

Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/run/desktop/mnt/host/e/Codes/docker-practice/docker-nodejs-sample/db/password.txt" to rootfs at "/run/secrets/db-password": mount /run/desktop/mnt/host/e/Codes/docker-practice/docker-nodejs-sample/db/password.txt:/run/secrets/db-password (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

Location

https://docs.docker.com/guides/nodejs/develop/

Suggestion

No response

@craig-osterhout
Copy link
Contributor

Thanks for sharing the issue.

Unfortunately, this looks like it may be a system-specific configuration issue.
For help troubleshooting, you can try the community Slack at https://join.slack.com/t/dockercommunity/shared_invite/zt-1jz09gjit-P2NPysg99kiWExFfof0oBA

You can try running a simple container that bind mounts that file in order to see if it fails.
For example:
docker run --rm -v "E:\Codes\docker-practice\docker-nodejs-sample\db\password.txt:/test-password.txt" alpine cat /test-password.txt

That'll run a alpine container, bind mount your password.txt file inside it, and then print out the password contained inside.

If you want to do a workaround and troubleshoot later, you can avoid using secrets.
For example:


services:
  server:
    build:
      context: .
    environment:
      NODE_ENV: production
      POSTGRES_HOST: db
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: mysecretpassword
      POSTGRES_DB: example
    ports:
      - 3000:3000

    depends_on:
      db:
        condition: service_healthy
  db:
    image: postgres
    restart: always
    user: postgres
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=example
      - POSTGRES_PASSWORD=mysecretpassword
    expose:
      - 5432
    healthcheck:
      test: ["CMD", "pg_isready"]
      interval: 10s
      timeout: 5s
      retries: 5
volumes:
  db-data:

For the above example, you can learn about the environment variables used at https://hub.docker.com/_/postgres and in the src/persistence/postgres.js file.

@minhsu12113
Copy link
Author

Thanks for sharing the issue.

Unfortunately, this looks like it may be a system-specific configuration issue. For help troubleshooting, you can try the community Slack at https://join.slack.com/t/dockercommunity/shared_invite/zt-1jz09gjit-P2NPysg99kiWExFfof0oBA

You can try running a simple container that bind mounts that file in order to see if it fails. For example: docker run --rm -v "E:\Codes\docker-practice\docker-nodejs-sample\db\password.txt:/test-password.txt" alpine cat /test-password.txt

That'll run a alpine container, bind mount your password.txt file inside it, and then print out the password contained inside.

If you want to do a workaround and troubleshoot later, you can avoid using secrets. For example:


services:
  server:
    build:
      context: .
    environment:
      NODE_ENV: production
      POSTGRES_HOST: db
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: mysecretpassword
      POSTGRES_DB: example
    ports:
      - 3000:3000

    depends_on:
      db:
        condition: service_healthy
  db:
    image: postgres
    restart: always
    user: postgres
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=example
      - POSTGRES_PASSWORD=mysecretpassword
    expose:
      - 5432
    healthcheck:
      test: ["CMD", "pg_isready"]
      interval: 10s
      timeout: 5s
      retries: 5
volumes:
  db-data:

For the above example, you can learn about the environment variables used at https://hub.docker.com/_/postgres and in the src/persistence/postgres.js file.

Thank for replying to me, I have no idea what happened, but today I'm tried remove postgresql image and re-pull it. After that, I ran docker cmd again, and it work for me without change anything in the compose file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants