2019-11-06 06:53:09 +00:00
|
|
|
|
# [Node.js](https://hub.docker.com/_/node/)
|
2016-12-10 09:00:25 +00:00
|
|
|
|
|
2019-11-06 06:53:09 +00:00
|
|
|
|
## 基本信息
|
2016-12-10 09:00:25 +00:00
|
|
|
|
|
2017-11-24 02:19:15 +00:00
|
|
|
|
[Node.js](https://en.wikipedia.org/wiki/Node.js) 是基于 JavaScript 的可扩展服务端和网络软件开发平台。
|
|
|
|
|
|
2020-04-26 02:34:02 +00:00
|
|
|
|
该仓库位于 `https://hub.docker.com/_/node/` ,提供了 Node.js 0.10 ~ 14.x 各个版本的镜像。
|
2016-12-10 09:00:25 +00:00
|
|
|
|
|
2019-11-06 06:53:09 +00:00
|
|
|
|
## 使用方法
|
2017-11-24 02:19:15 +00:00
|
|
|
|
|
2016-12-10 09:00:25 +00:00
|
|
|
|
在项目中创建一个 Dockerfile。
|
|
|
|
|
|
2021-03-20 03:22:13 +00:00
|
|
|
|
```docker
|
2019-09-20 08:51:04 +00:00
|
|
|
|
FROM node:12
|
2016-12-10 09:00:25 +00:00
|
|
|
|
# replace this with your application's default port
|
|
|
|
|
EXPOSE 8888
|
|
|
|
|
```
|
2017-11-24 02:19:15 +00:00
|
|
|
|
|
2016-12-10 09:00:25 +00:00
|
|
|
|
然后创建镜像,并启动容器。
|
|
|
|
|
|
2017-11-22 03:13:23 +00:00
|
|
|
|
```bash
|
2016-12-10 09:00:25 +00:00
|
|
|
|
$ docker build -t my-nodejs-app
|
|
|
|
|
$ docker run -it --rm --name my-running-app my-nodejs-app
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
也可以直接运行一个简单容器。
|
|
|
|
|
|
2017-11-22 03:13:23 +00:00
|
|
|
|
```bash
|
2017-12-01 09:32:39 +00:00
|
|
|
|
$ docker run -it --rm \
|
|
|
|
|
--name my-running-script \
|
|
|
|
|
# -v "$(pwd)":/usr/src/myapp \
|
|
|
|
|
--mount type=bind,src=`$(pwd)`,target=/usr/src/myapp \
|
|
|
|
|
-w /usr/src/myapp \
|
2019-09-20 08:51:04 +00:00
|
|
|
|
node:12-alpine \
|
2017-12-01 09:32:39 +00:00
|
|
|
|
node your-daemon-or-script.js
|
2016-12-10 09:00:25 +00:00
|
|
|
|
```
|
|
|
|
|
|
2019-11-06 06:53:09 +00:00
|
|
|
|
## Dockerfile
|
2016-12-10 09:00:25 +00:00
|
|
|
|
|
2017-10-31 16:36:57 +00:00
|
|
|
|
请到 https://github.com/docker-library/docs/tree/master/node 查看。
|