CentOS7 Docker Nginx部署及運行詳解
網(wǎng)上找了一些資料部署,出現(xiàn)不一樣的問題,現(xiàn)在總結一下自己的部署流程。
1、資源準備
Dockerfile文件
# "ported" by Adam Miller <maxamillion@fedoraproject.org> from # https://github.com/fedora-cloud/Fedora-Dockerfiles # # Originally written for Fedora-Dockerfiles by # scollier <scollier@redhat.com> FROM centos:centos7 MAINTAINER The CentOS Project <cloud-ops@centos.org> RUN yum -y update; yum clean all RUN yum -y install epel-release tar ; yum clean all RUN yum -y install nginx ; yum clean all ADD nginx.conf /opt/deploy/nginx/nginx.conf RUN echo "daemon off;" >> /opt/deploy/nginx/nginx.conf #RUN curl https://git.centos.org/sources/httpd/c7/acf5cccf4afaecf3afeb18c50ae59fd5c6504910 \ # | tar -xz -C /usr/local/nginx/html \ # --strip-components=1 #RUN sed -i -e 's/Apache/nginx/g' -e '/apache_pb.gif/d' \ # /usr/local/nginx/html/index.html EXPOSE 80 #CMD [ "/usr/local/nginx/sbin" ]
注意:路徑需要在系統(tǒng)上面存在以及對應
nginx.conf文件
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes 1; error_log /usr/logs/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; pid /run/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_age
注意:路徑需要在系統(tǒng)上面存在以及對應
2、執(zhí)行構建鏡像命令
[root@localhost nginx]# sudo docker build --rm --tag os7/nginx:centos7 .
執(zhí)行結果截圖:
3、查看鏡像是否安裝構建成功 Docker images
4、創(chuàng)建容器 docker run -i -t -d -p 192.168.32.129:81:80 os7/nginx /bin/bash
注意:192.168.32.129這個IP的話,則需要在/etc/hosts中添加
192.168.32.129 localhost
5、查看容器是否創(chuàng)建成功并啟動 docker ps
6、測試是否成功訪問 curl http://192.168.32.129:81
會出現(xiàn)這個拒絕連接,那怎么辦呢?有辦法解決的,我們先進入該容器里面
7、進入容器 docker exec -i -t small_hodgkin /bin/sh
8、接著在容器里面執(zhí)行(直接輸入即可)
nginx
9、在容器外面執(zhí)行 curl http://192.168.32.129:81
成功了。
10、再到虛擬機外面通過瀏覽器訪問
到此為止就成功了。
參考資料:https://github.com/CentOS/CentOS-Dockerfiles
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持本站。
版權聲明:本站文章來源標注為YINGSOO的內容版權均為本站所有,歡迎引用、轉載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內容涉嫌侵權,請聯(lián)系alex-e#qq.com處理。