You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
simple-node-app latest 93bbb19457f2 18 seconds ago 673MB
node latest ec70562ad6f0 3 days ago 673MB
三、运行容器
使用 docker run(等同于 docker container run)运行容器:
$ docker run --rm -it -p 9090:8080 simple-node-app
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0ba262d81a87 simple-node-app "node index.js" 4 minutes ago Up 4 minutes 0.0.0.0:9090->8080/tcp adoring_volhard
最近开发一个 Node.js 应用时初次接触到了 Docker,用到了不少 Docker 的命令,这里记录一下方便自己查看。
这篇文章不会详细解释每个命令是做什么的,权当作一个入门 Docker 的提纲吧。
假设我们有一个如下几行代码的 Node.js 应用:
一、编写 Dockerfile
首先,将应用部署在 Docker 中的第一步就是为它编写一个 Dockerfile:
提问:
CMD
与ENTRYPOINT
有什么不同?二、编译镜像
使用
docker build
(等同于docker image build
)编译一个镜像:运行
docker images
(等同于docker image list
)可以查看所有镜像:三、运行容器
使用
docker run
(等同于docker container run
)运行容器:提问:
--rm
、-it
与-p
的作用?现在打开 http://localhost:9090 就能看到
hello docker
了。使用
docker ps
(等同于docker container ls
)查看运行中的容器:添加
-a
参数就能看到停止的容器了。运行
lsof -nP -iTCP -sTCP:LISTEN
查看端口占用情况:四、查看容器运行状态
进入容器的 shell:
查看运行中的 Node.js 进程:
退出容器的 shell:
五、停止容器
使用
docker stop
(等同于docker container stop
)停止容器。提问:可以在运行容器命令窗口使用
Ctrl + C
停止容器吗?如果不可以,为什么?推荐文档
The text was updated successfully, but these errors were encountered: