Skip to content

nodejs部署 #1

@wuyuedefeng

Description

@wuyuedefeng

利用Dockerfile构建镜像

新建Dockerfile

FROM node:12.6.0-alpine

WORKDIR /app

RUN npm install pm2 -g  --registry=https://registry.npm.taobao.org
COPY package.json package-lock.json ./
RUN npm install --production --registry=https://registry.npm.taobao.org
# 等价于 COPY . /app/
COPY . . 

EXPOSE 3333

CMD ["pm2-runtime", "ecosystem.config.js"]

新建.dockerignore

docker-compose.env
docker-compose.yml
Dockerfile
node_modules
test
logs
.vscode
.idea
.git

构建镜像

$ docker build -t [image]:[version] .

启动镜像, 将本地5000端口映射到docker的3333端口上

$ docker run -d -p 5000:3333 --name="[container]" [image]:[version]
# $ docker logs [container] 可以查看日志

w3c docker教程

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions