Dockerfile
FROM node:10
# Create app directory
WORKDIR /usr/server
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json /usr/server/
RUN npm install
# If you are building your code for production
# RUN npm ci --only=production
# Bundle app source
COPY . /usr/server/
EXPOSE 3000
CMD [ "node", "./bin/www.js" ]`
然后我运行
docker run -d -p 3000:3000 chatapp-back
-e DB_HOST="mongodb://localhost:27017/"
-e DB_USER="user"
-e DB_NAME="dbname"
-e DB_PASS="dbpass"
-e JWT_SECRET="my-jwt-secret"
使用docker logs <container-id>
命令查看控制台输出
[eval]:1
JWT_SECRET=my-jwt-secret
^
ReferenceError: my is not defined
at [eval]:1:1
at Script.runInThisContext (vm.js:122:20)
at Object.runInThisContext (vm.js:329:38)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at evalScript (internal/bootstrap/node.js:590:27)
at startup (internal/bootstrap/node.js:265:9)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
我也尝试了使用
docker run -d -p 3000:3000 chatapp-back --env-file .env
命令,但是控制台返回了以下结果。node: bad option: --env-file
我在这里做错了什么
我使用了Docker运行文档
docker run -e
选项;它们需要在镜像名称之前。 - David Maze