创建nginx镜像(提供配置文件和网页文件)
#拉取镜像
[root@localhost ~]# docker pull neawalke/nginx:v2.0
v2.0: Pulling from neawalke/nginx
a1d0c7532777: Already exists
85731d77a16c: Pull complete
716b1ea9bb1a: Pull complete
Digest: sha256:fbdb7ed8e30110b5d3e5ab90c968bd1c148adec36fa70afcbc468bdc0ef101ad
Status: Downloaded newer image for neawalke/nginx:v2.0
docker.io/neawalke/nginx:v2.0
#将网页文件放在/var/www/html下
[root@localhost ~]# ls /var/www/html/
images index.html scripts sound
#创建一个配置nginx网页的容器
[root@localhost ~]# docker run -it --name html -v /var/www/html:/usr/local/nginx/html neawalke/nginx:v2.0
[root@localhost ~]# docker exec -it html /bin/bash
[root@74ab2e5f4111 /]# ls /usr/local/nginx/html/
images index.html scripts sound
#将nginx的配置文件拷贝到本机上
[root@localhost ~]# docker container cp -a html:/usr/local/nginx/conf/ /config/
[root@localhost ~]# ls /config/
conf
[root@localhost ~]# ls /config/conf/
fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params
fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default
fastcgi_params koi-win nginx.conf scgi_params.default win-utf
#创建一个nginx配置文件的容器
[root@localhost ~]# docker run -d --name nginx_conf --volumes-from html -v /config/conf:/usr/local/nginx/conf neawalke/nginx:v2.0
[root@localhost ~]# docker run -it --name web -p 80:80 --volumes-from nginx_conf neawalke/nginx:v2.0
修改配置文件
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
images index.html scripts sound
[root@localhost html]# mkdir game
[root@localhost html]# mv images index.html scripts sound game/
[root@localhost html]# ls
game
[root@localhost html]# mkdir test
[root@localhost html]# echo "hello word" > test/index.html
[root@localhost html]# cd /config/conf/
[root@localhost conf]# vim nginx.conf
server {
listen 80;
server_name test.example.com;
location / {
root /usr/local/nginx/html/test;
index index.html;
}
}
server {
listen 8080;
server_name game.example.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/local/nginx/html/game;
index index.html index.htm;
}
[root@localhost conf]# docker run -it --name web -p 80:80 -p 8080:8080 --volumes-from nginx_conf neawalke/nginx:v2.0