Mis*_*one 6 node.js docker google-cloud-run
我是 Docker 方面的超级新手,最近将一个项目从 App Engine 移至 Cloud Run。很简单,很喜欢。
然而,现在我正在尝试更新图像(因为我添加了一些新代码)。我知道我需要进入实际的容器来更新图像(我认为?),但是当我尝试这样做时docker run,我收到unexpected operator错误。
这让我彻底抓狂。
我无法启动容器。我无法编辑我的图像。我无法在 Cloud Run 上上传新版本。
据我所知,unexpected operator错误必须处理 Dockerfile。这是我的 Dockerfile(由 Google 提供,用于在 Cloud Run 上部署映像)。
Dockerfile
#Use the official Node.js 10 image
#https://hub.docker.com/_/node
FROM node:10
#Create and change to the app directory
WORKDIR /usr/src/app
#Copy application dependency manifests to the container image.
#A wild card is used to ensure both package.json AND package-lock.json are copied.
#Copying this separately prevents re0running npm install on every code change.
COPY *package.json ./
#Install production dependences
RUN npm install --only=production
#COPY local code to the container image
COPY . .
#Run the web service on container startup
CMD [ "npm", "start" ]
Run Code Online (Sandbox Code Playgroud)
unexpected operator我收到的具体错误是/bin/sh: 1: [: npm.: unexpected operator
老实说,我现在不知道该怎么办。我想我需要第二双眼睛来审视它。
小智 12
我敢打赌,当您提供代码片段时,您有意或无意地清理了代码,CMD [ "npm", "start" ]几乎可以肯定是CMD [ "npm" "start" ]
在您最初构建映像并尝试将其作为容器运行时。
分解错误消息:/bin/sh: 1: [: npm.: unexpected operator
它告诉您 shell 脚本在第一行有问题。哪个 shell 脚本?由 CMD 行触发的 shell 脚本。第 1 行部分是因为,在 CMD 运行的上下文中,这是唯一的一行。
然后,它非常难以辨认地表示,在 npm 声明之后出现了问题。意外导致这种情况的最简单方法就是忘记逗号。
鉴于您显然能够稍后让事情运行,您很可能:
每次更改后都必须从 Dockerfile 重建映像
docker build --tag="npm_app:latest" -f Dockerfile .
docker run npm_app
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10044 次 |
| 最近记录: |