I'm trying to run docker run ID npm run test
but I get the following error: docker-entrypoint.sh: 38: exec: npm: not found
.
我正在尝试运行docker run ID npm运行测试,但收到以下错误:docker-entry ypoint t.sh:38:exec:npm:Not Found。
I'm very new to Docker and I tried this (adding the entrypoint ENTRYPOINT ["/usr/src/app/api-entrypoint.sh"]
) but it doesn't seem to work.
我是Docker的新手,我尝试过这个方法(添加入口点入口点[“/usr/src/app/api-entrypoint t.sh”]),但似乎不起作用。
What do I need to change?
我需要改变什么?
Dockerfile
文档文件
FROM node:13.12.0-alpine as builder
WORKDIR '/app'
COPY package.json .
RUN npm install
COPY . .
RUN npm run build
FROM nginx
COPY --from=builder /app/build /usr/share/nginx/html
更多回答
优秀答案推荐
the entrypoint is running on the second image, the nginx one, which does not have npm
入口点在第二个映像上运行,即nginx映像,它没有npm
This Dockerfile you've provided was for production purposes. Before that, you built one docker file for the development environment. By creating and running a container using that docker file, you can solve this issue.
I'm guessing your development docker file name is something like Dockerfile.dev. So the solution would be something like,
您提供的文档文件用于生产目的。在此之前,您为开发环境构建了一个docker文件。通过使用该停靠文件创建和运行容器,可以解决此问题。我猜您的开发docker文件名类似于Dockerfile.dev。因此,解决方案应该是这样的,
Building a container
构建一个容器
docker build -t username/repository-name -f ./Dockerfile.dev .
Running that docker container and overriding the primary command using the following command
运行Docker容器并使用以下命令覆盖主命令
docker run username/repository-name npm run test -- --coverage
'username/repository' could be anything you want, it's a conversion to tag your container.
‘用户名/储存库’可以是你想要的任何东西,它是标记你的容器的转换。
更多回答
I don't really know what an entrypoint is in Docker or how to properly fix it
我真的不知道Docker中的入口点是什么,也不知道如何正确地修复它
no worries i will try to explain. You are using a multi stage build: docs.docker.com/develop/develop-images/multistage-build in short, you are using an image to perform a couple of actions and then you are copying to a second image something from the first one. An image is just an image like a vm. It does not do anything. If you need to run something when the image is up you need an entrypoint which will execute stuff. I would suggest to creat your image, spin up a container and run manually the entrypoint until you get good results. Then you can copy the entrypoint on build time.
别担心,我会尽力解释的。您正在使用多阶段构建:docs.docker.com/develop/develop-images/multistage-build简而言之,您正在使用一个映像来执行几个操作,然后将第一个映像中的内容复制到第二个映像中。映像只是一个类似于VM的映像。它什么也做不了。如果您需要在映像打开时运行某些内容,则需要一个入口点来执行某些内容。我建议创建你的图像,旋转一个容器,手动运行入口点,直到你得到好的结果。然后,您可以在构建时复制入口点。
我是一名优秀的程序员,十分优秀!