CentOS7 Docker Nginx部署及運(yùn)行詳解
網(wǎng)上找了一些資料部署,出現(xiàn)不一樣的問(wèn)題,現(xiàn)在總結(jié)一下自己的部署流程。
1、資源準(zhǔn)備
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)上面存在以及對(duì)應(yī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)上面存在以及對(duì)應(yīng)
2、執(zhí)行構(gòu)建鏡像命令
[root@localhost nginx]# sudo docker build --rm --tag os7/nginx:centos7 .
執(zhí)行結(jié)果截圖:

3、查看鏡像是否安裝構(gòu)建成功 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這個(gè)IP的話,則需要在/etc/hosts中添加
192.168.32.129 localhost
5、查看容器是否創(chuàng)建成功并啟動(dòng) docker ps

6、測(cè)試是否成功訪問(wèn) curl http://192.168.32.129:81

會(huì)出現(xiàn)這個(gè)拒絕連接,那怎么辦呢?有辦法解決的,我們先進(jìn)入該容器里面
7、進(jìn)入容器 docker exec -i -t small_hodgkin /bin/sh

8、接著在容器里面執(zhí)行(直接輸入即可)
nginx
9、在容器外面執(zhí)行 curl http://192.168.32.129:81

成功了。
10、再到虛擬機(jī)外面通過(guò)瀏覽器訪問(wèn)

到此為止就成功了。
參考資料:https://github.com/CentOS/CentOS-Dockerfiles
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持本站。
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信