前言
前一天你已经安装好了 docker,今天你将运行第一个 docker 程序 nginx 。
启动 nginx
docker run --name nginx -d -p 80:80 nginx:latest
指令解析:
"docker run":启动 docker 容器
"--name nginx":设置容器名称为 nginx
"-d":后台运行
"-p 80:80":把宿主机的 80 端口映射到容器的 80 端口,格式为 -p {宿主机端口}:{容器端口}
"nginx:latest":使用镜像,这里是 nginx 最新版本的镜像,格式为 {镜像名称}:{镜像版本}
查看镜像
docker images
查看运行中的容器
docker ps
访问 nginx
- 浏览器访问
- 服务器指令访问
curl http://localhost
暂停 nginx
docker stop nginx
docker ps -a
删除 nginx
docker rm nginx
docker ps -a
总结
按照上述的操作,今天应该可以成功运行第一个 docker 程序,明天我们将进入我们运行的 docker 程序。
如有问题可以在文章留言,或添加公众号【跬步之巅】进行交流。