新聞中心
方法一、通過(guò) dockerfile構(gòu)建
創(chuàng)建Dockerfile

成都創(chuàng)新互聯(lián)秉承實(shí)現(xiàn)全網(wǎng)價(jià)值營(yíng)銷(xiāo)的理念,以專(zhuān)業(yè)定制企業(yè)官網(wǎng),網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作,小程序設(shè)計(jì),網(wǎng)頁(yè)設(shè)計(jì)制作,成都做手機(jī)網(wǎng)站,網(wǎng)絡(luò)營(yíng)銷(xiāo)推廣幫助傳統(tǒng)企業(yè)實(shí)現(xiàn)“互聯(lián)網(wǎng)+”轉(zhuǎn)型升級(jí)專(zhuān)業(yè)定制企業(yè)官網(wǎng),公司注重人才、技術(shù)和管理,匯聚了一批優(yōu)秀的互聯(lián)網(wǎng)技術(shù)人才,對(duì)客戶都以感恩的心態(tài)奉獻(xiàn)自己的專(zhuān)業(yè)和所長(zhǎng)。
首先,創(chuàng)建目錄nginx,用于存放后面的相關(guān)東西。
~$ mkdir -p ~/nginx/www ~/nginx/logs ~/nginx/conf
www目錄將映射為nginx容器配置的虛擬目錄
logs目錄將映射為nginx容器的日志目錄
conf目錄里的配置文件將映射為nginx容器的配置文件
進(jìn)入創(chuàng)建的nginx目錄,創(chuàng)建Dockerfile
FROM debian:jessie MAINTAINER NGINX Docker Maintainers "[email protected]" ENV NGINX_VERSION 1.10.1-1~jessie RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 \ && echo "deb http://nginx.org/packages/debian/ jessie nginx" >> /etc/apt/sources.list \ && apt-get update \ && apt-get install --no-install-recommends --no-install-suggests -y \ ca-certificates \ nginx=${NGINX_VERSION} \ nginx-module-xslt \ nginx-module-geoip \ nginx-module-image-filter \ nginx-module-perl \ nginx-module-njs \ gettext-base \ && rm -rf /var/lib/apt/lists/* # forward request and error logs to docker log collector RUN ln -sf /dev/stdout /var/log/nginx/access.log \ && ln -sf /dev/stderr /var/log/nginx/error.log EXPOSE 80 443 CMD ["nginx", "-g", "daemon off;"]
通過(guò)Dockerfile創(chuàng)建一個(gè)鏡像,替換成你自己的名字
docker build -t nginx .
創(chuàng)建完成后,我們可以在本地的鏡像列表里查找到剛剛創(chuàng)建的鏡像
[email protected]:~/nginx$ docker images nginx REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 555bbd91e13c 3 days ago 182.8 MB
方法二、docker pull nginx
查找Docker Hub上的nginx鏡像
[email protected]:~/nginx$ docker search nginx NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 3260 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker c... 674 [OK] richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable ... 207 [OK] million12/nginx-php Nginx + PHP-FPM 5.5, 5.6, 7.0 (NG), CentOS... 67 [OK] maxexcloo/nginx-php Docker framework container with Nginx and ... 57 [OK] webdevops/php-nginx Nginx with PHP-FPM 39 [OK] h3nrik/nginx-ldap NGINX web server with LDAP/AD, SSL and pro... 27 [OK] bitnami/nginx Bitnami nginx Docker Image 19 [OK] maxexcloo/nginx Docker framework container with Nginx inst... 7 [OK] ...
這里我們拉取官方的鏡像
[email protected]:~/nginx$ docker pull nginx
等待下載完成后,我們就可以在本地鏡像列表里查到REPOSITORY為nginx的鏡像。
使用nginx鏡像
運(yùn)行容器
[email protected]:~/nginx$ docker run -p 80:80 --name mynginx -v $PWD/www:/www -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/logs:/wwwlogs -d nginx 45c89fab0bf9ad643bc7ab571f3ccd65379b844498f54a7c8a4e7ca1dc3a2c1e [email protected]:~/nginx$
命令說(shuō)明:
-
-p 80:80:將容器的80端口映射到主機(jī)的80端口
-
--name mynginx:將容器命名為mynginx
-
-v $PWD/www:/www:將主機(jī)中當(dāng)前目錄下的www掛載到容器的/www
-
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf:將主機(jī)中當(dāng)前目錄下的nginx.conf掛載到容器的/etc/nginx/nginx.conf
-
-v $PWD/logs:/wwwlogs:將主機(jī)中當(dāng)前目錄下的logs掛載到容器的/wwwlogs
查看容器啟動(dòng)情況
[email protected]:~/nginx$ docker ps CONTAINER ID IMAGE COMMAND PORTS NAMES 45c89fab0bf9 nginx "nginx -g 'daemon off" ... 0.0.0.0:80->80/tcp, 443/tcp mynginx f2fa96138d71 tomcat "catalina.sh run" ... 0.0.0.0:81->8080/tcp tomcat
通過(guò)瀏覽器訪問(wèn)
新聞名稱(chēng):創(chuàng)新互聯(lián)Docker教程:Docker安裝Nginx
URL鏈接:http://m.fisionsoft.com.cn/article/dppojgd.html


咨詢
建站咨詢
