這篇文章主要介紹CentOS7 Docker Nginx部署及運行的示例分析,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
創(chuàng)新互聯(lián)服務項目包括臨沂網站建設、臨沂網站制作、臨沂網頁制作以及臨沂網絡營銷策劃等。多年來,我們專注于互聯(lián)網行業(yè),利用自身積累的技術優(yōu)勢、行業(yè)經驗、深度合作伙伴關系等,向廣大中小型企業(yè)、政府機構等提供互聯(lián)網行業(yè)的解決方案,臨沂網站推廣取得了明顯的社會效益與經濟效益。目前,我們服務的客戶以成都為中心已經輻射到臨沂省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!
1、資源準備
Dockerfile文件
# "ported" by Adam Millerfrom # https://github.com/fedora-cloud/Fedora-Dockerfiles # # Originally written for Fedora-Dockerfiles by # scollier FROM centos:centos7 MAINTAINER The CentOS Project 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_agent" "$http_x_forwarded_for"'; access_log /usr/logs/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. #include /etc/nginx/conf.d/*.conf; index index.html index.htm; server { listen 80; server_name localhost; root /usr/share/nginx/html; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { autoindex on; } # redirect server error pages to the static page /40x.html # error_page 404 /404.html; location = /40x.html { } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # root html; # location / { # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # root html; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # } #} }
注意:路徑需要在系統(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、再到虛擬機外面通過瀏覽器訪問
到此為止就成功了。
以上是“CentOS7 Docker Nginx部署及運行的示例分析”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!