Docker中運(yùn)行nginx并掛載本地目錄到鏡像中的方法
1 從hup上pull鏡像
docker pull nginx
2 創(chuàng)建將要掛載的目錄
mkdir -p /data/nginx/{conf,conf.d,html,logs}
3 先要有配置文件才能啟動(dòng)容器
3.1 vim /data/conf/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
3.2 vim /data/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /data/nginx/html;
# root /usr/nginx/html;
index index.html index.htm;
autoindex on;
try_files $uri /index/index/page.html;
#try_files $uri /index/map/page.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/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;
#}
}
4 啟動(dòng)容器
#將容器中nginx的80端口映射到本地的81端口 docker run --name nginx81 -d -p 81:80 -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/logs:/var/log/nginx -v /data/nginx/conf.d:/etc/nginx/conf.d -d nginx:latest
5 查看啟動(dòng)的容器
[root@dc01 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fa56f865bd26 nginx:latest "nginx -g 'daemon of…" 4 weeks ago Up 3 seconds 0.0.0.0:80->80/tcp vigilant_swirles [root@dc01 ~]#
6 網(wǎng)頁(yè)訪問(wèn)nginx

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Docker安裝方法與Docker四種網(wǎng)絡(luò)模式詳解
今天小編就為大家分享一篇關(guān)于Docker安裝方法與Docker四種網(wǎng)絡(luò)模式的詳解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-09-09
CentOS 7.x docker使用overlay2存儲(chǔ)方式
這篇文章主要介紹了CentOS 7.x docker使用overlay2存儲(chǔ)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11
Docker Registry 私有倉(cāng)庫(kù)搭建詳細(xì)步驟
這篇文章主要介紹了Docker Registry 私有倉(cāng)庫(kù)搭建的相關(guān)資料,需要的朋友可以參考下2016-10-10
Windows?Server?2012?R2?安裝?Docker的詳細(xì)步驟
這篇文章主要介紹了Windows?Server?2012?R2?安裝?Docker,在這個(gè)給大家說(shuō)明下使用windows10、Windows?Server?2016以上系統(tǒng)可直接使用安裝包,低版本系統(tǒng)需要使用?Docker?Toolbox?來(lái)進(jìn)行安裝使用?Docker,需要的朋友可以參考下2022-04-04
詳解使用export/import導(dǎo)出和導(dǎo)入docker容器
本篇文章主要介紹了詳解使用export/import導(dǎo)出和導(dǎo)入docker容器,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07
docker 安裝nacos并配置數(shù)據(jù)庫(kù)的教程詳解
這篇文章主要介紹了docker 安裝nacos并配置數(shù)據(jù)庫(kù)的教程詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12
jenkins中通過(guò)Publish Over SSH插件將項(xiàng)目部署到遠(yuǎn)程機(jī)器上的講解說(shuō)明
今天小編就為大家分享一篇關(guān)于jenkins中通過(guò)Publish Over SSH插件將項(xiàng)目部署到遠(yuǎn)程機(jī)器上的講解說(shuō)明,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-02-02
win7環(huán)境下Docker快速構(gòu)建及阿里云容器加速配置詳解
這篇文章主要介紹了win7環(huán)境下Docker快速構(gòu)建及阿里云容器加速配置詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
docker?搭建?ElasticSearch過(guò)程解析
這篇文章主要介紹了docker搭建ElasticSearch的過(guò)程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,,需要的朋友可以參考下2023-08-08
Docker跨主機(jī)網(wǎng)絡(luò)(overlay)的實(shí)現(xiàn)
這篇文章主要介紹了Docker跨主機(jī)網(wǎng)絡(luò)(overlay)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12

