docker安装nginx

windows下安装:

1,拉取最新镜像:docker pull nginx
2,docker images 查看镜像
3,cmd Dockerfile
4,touch Dockerfile
5,vim Dockerfile 加入下面的内容,以 nginx 作为基础镜像,执行输出 hello docker! 到 index.html 中 ,这里可以不需要,直接运行容器访问的是 nginx 的默认页面
  FROM nginx
  RUN echo '<h1>hello docker!</h1>' > /usr/share/nginx/html/index.html
6,在 Dockerfile 的同级目录下执行  docker build -t nginx:V1 .  //最后有一个. 表示当前目录,标签为V1
7,docker images 查看所有镜像, v1 的这个就是你的
//将主要的文件 -v 挂载出来
8,docker run -d --name mynginx_V1 -p 8099:80 -v D:\software\dockerfile\html:/usr/share/nginx/html -v D:\software\dockerfile\conf\nginx.conf:/etc/nginx/conf.d/default.conf -v D:\software\dockerfile\logs:/var/log/nginx nginx:V1

9,localhost:8099 就可以进行访问

10,如果需要访问自己的前端页面,将页面放在 D:\software\dockerfile\html 目录下,重新运行容器即可(stop,run)

posted @ 2020-12-21 17:09  陌小但  阅读(306)  评论(0编辑  收藏  举报