1.程序根目錄建立Dockerfile
文件node
FROM node:11.2.0 # 表示node環境基礎鏡像
WORKDIR /apis/nodeAppServer # docker工做目錄
COPY . /apis/nodeAppServer # 當前程序拷貝到docker工做目錄
RUN npm install # 執行linux命令,安裝程序依賴包
CMD [ "node","server" ] # 執行linux命令,運行node程序
複製代碼
目錄結構:linux
2.放到linux環境
docker
構建鏡像npm
docker build -t nodeAppServer .
複製代碼
構建成功後查看鏡像docker images
api
[root@localhost nodeAppServer]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nodeAppServer latest 6c5d3ccf3af0 12 seconds ago 900 MB
複製代碼
3.運行docker
容器bash
docker run -d --name nodeAppServer -p 8068:8068 nodeAppServer
複製代碼
docker ps
查看正在運行的容器curl
docker logs 容器名稱
查看容器錯誤日誌tcp
[root@localhost nodeAppServer]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
83130c5100a8 nodeAppServer "node server" 2 seconds ago Up 1 second 0.0.0.0:8068->8068/tcp nodeAppServer
複製代碼
訪問應用ui
注意開啓防火牆端口哈 firewall-cmd --zone=public --add-port=8068/tcp --permanent firewall-cmd --reload url
[root@localhost nodeAppServer]# curl http://localhost:8068/project/yourparams
複製代碼