docker运行nginx

Dockerfile

FROM nginx
RUN ["apt-get","update"]
RUN ["apt-get","install","-y","vim"]
# 以\ 与 && 符号连接命令,这样执行后,只会创建 1 层镜像.避免镜像膨胀过大
RUN echo '这是一个本地构建的nginx镜像' > /usr/share/nginx/html/index.html \
        && echo '用来提供一个简单的文件下载功能' >> /usr/share/nginx/html/index.html \
        && mkdir -p /usr/local/nginx_down/ocotpus_http_download
COPY ./server.conf /etc/nginx/conf.d/default.conf
#定义匿名数据卷。在启动容器时忘记挂载数据卷,会自动挂载到匿名卷
#通过 VOLUME 指令创建的挂载点,无法指定主机上对应的目录,是自动生成的
VOLUME ["/usr/local/nginx_down/ocotpus_http_download/"]

构建镜像

docker build -t octopus_rpm_nginx .

运行

  • 端口映射到本机8081
  • 映射了本机的目录/usr/local/nginx_down/ocotpus_http_download/
  • –rm 关闭容器时,删除容器
docker run -d  -p 192.168.8.73:8081:80 \
-v /usr/local/nginx_down/ocotpus_http_download/:/usr/local/nginx_down/ocotpus_http_download/ \
--rm \
--name rpmnginx  octopus_rpm_nginx

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.