问题在Mac M1的Docker中启动Nodemon

发布于 2025-02-04 02:00:52 字数 1956 浏览 3 评论 0原文

我正在尝试在Mac M1上运行Docker内部运行的Barybones节点/Express应用程序,但是当我尝试旋转Docker容器时,我会遇到以下错误:

> docker run -p 3000:8080 --name my-container --volume ${PWD}:/usr/src/app my-app

yarn run v1.22.19
$ nodemon server.js
/bin/sh: nodemon: Device timeout
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

如果我本地运行'start'命令,我会得到无问题:

> yarn start
yarn run v1.22.18
$ nodemon server.js
[nodemon] 2.0.16
[nodemon] reading config ./package.json
[nodemon] to restart at any time, enter `rs`
[nodemon] or send SIGHUP to 6511 to restart
[nodemon] ignoring: node_modules/**/* docs/**/*
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
[nodemon] forking
[nodemon] child pid: 6513
[nodemon] watching 6 files
Example app listening at http://localhost:8080

我的package.json看起来像这样:

{
  "name": "docker-template",
  "version": "1.0.0",
  "main": "server.js",
  "license": "MIT",
  "dependencies": {
    "express": "^4.18.1",
    "pg": "^8.7.3"
  },
  "devDependencies": {
    "nodemon": "^2.0.16"
  },
  "scripts": {
    "start": "nodemon server.js"
  },
  "nodemonConfig": {
    "ignore": [
      "node_modules/*",
      "docs/*"
    ],
    "verbose": true,
    "delay": 2500
  }
}

...我的dockerfile看起来像这样:

# select the base image
FROM node:14-alpine3.15

# Adding build tools to make yarn install work on Apple silicon / arm64 machines
RUN apk add --no-cache python2 g++ make

WORKDIR /usr/src/app

# Install app dependencies

COPY package.json ./
COPY yarn.lock ./

RUN yarn install

COPY . .

EXPOSE 8080

CMD [ "yarn", "start"]

您可以看到我尝试添加手表延迟,并明确排除node_modules。我很明显吗?

I'm attempting to get a barebones node/express app running inside docker on a Mac M1, but I'm getting the following error when I try to spin up the Docker container:

> docker run -p 3000:8080 --name my-container --volume ${PWD}:/usr/src/app my-app

yarn run v1.22.19
$ nodemon server.js
/bin/sh: nodemon: Device timeout
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

If I run the 'start' command locally, I get no issue:

> yarn start
yarn run v1.22.18
$ nodemon server.js
[nodemon] 2.0.16
[nodemon] reading config ./package.json
[nodemon] to restart at any time, enter `rs`
[nodemon] or send SIGHUP to 6511 to restart
[nodemon] ignoring: node_modules/**/* docs/**/*
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
[nodemon] forking
[nodemon] child pid: 6513
[nodemon] watching 6 files
Example app listening at http://localhost:8080

My package.json looks like this:

{
  "name": "docker-template",
  "version": "1.0.0",
  "main": "server.js",
  "license": "MIT",
  "dependencies": {
    "express": "^4.18.1",
    "pg": "^8.7.3"
  },
  "devDependencies": {
    "nodemon": "^2.0.16"
  },
  "scripts": {
    "start": "nodemon server.js"
  },
  "nodemonConfig": {
    "ignore": [
      "node_modules/*",
      "docs/*"
    ],
    "verbose": true,
    "delay": 2500
  }
}

... and my Dockerfile looks like this:

# select the base image
FROM node:14-alpine3.15

# Adding build tools to make yarn install work on Apple silicon / arm64 machines
RUN apk add --no-cache python2 g++ make

WORKDIR /usr/src/app

# Install app dependencies

COPY package.json ./
COPY yarn.lock ./

RUN yarn install

COPY . .

EXPOSE 8080

CMD [ "yarn", "start"]

As you can see I've tried adding a watch delay and explicitly excluding node_modules. Is there something obvious I'm missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里人 2025-02-11 02:00:52

好吧,事实证明,这是一个混蛋问题,因为我被送给我工作的机器将Podman拒绝向Docker。因此,问题归于Podman。 Podman被拆除并由Docker取代了Dockerfile完美运行!

Ok, turns out it was down to an aliasing issue, in that the machine I'd been given to work on had podman aliased to docker. So the issue was down to podman. With podman removed and replaced by docker the Dockerfile ran perfectly!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文