创建nginx容器
需要同时提供配置文件和网页文件
[root@localhost ~]# docker run -d --name nginx 1225514226/nginx:v2.0
bf7d4417b6d858520dad5f5d13498ae7cbdf5c071614189c7ce05bcb9f8e5976
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bf7d4417b6d8 1225514226/nginx:v2.0 "/usr/local/nginx/sb…" 3 seconds ago Up 2 seconds nginx
[root@localhost ~]# docker cp nginx:/usr/local/nginx/conf .
[root@localhost ~]# docker cp nginx:/usr/local/nginx/html .
[root@localhost ~]# ls
anaconda-ks.cfg apache conf html
[root@localhost ~]# mkdir config
[root@localhost ~]# mv conf html config/
[root@localhost ~]# cd config/
[root@localhost config]# ls
conf html
[root@localhost config]# ls conf/
fastcgi.conf koi-utf nginx.conf uwsgi_params
fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default
fastcgi_params mime.types scgi_params win-utf
fastcgi_params.default mime.types.default scgi_params.default
[root@localhost config]# mkdir html/test
[root@localhost config]# echo "hello world" > html/test/index.html
[root@localhost config]# ls html/
images index.html jquery.js QAuIByrkL.js test VNkyVaVxUV.css wNGu2CtEMx.js
[root@localhost config]#
nginx配置文件配置虚拟主机
[root@localhost config]# vim conf/nginx.conf
·····省略部分······
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
server {
listen 8080;
server_name test.example.com;
location / {
root html/test;
index index.html index.htm;
}
}
····省略部分····
删除刚刚创建的容器
[root@localhost config]# docker rm -f nginx
nginx
##删除后文件还在
[root@localhost config]# ls
conf html
[root@localhost config]# ls conf/
fastcgi.conf koi-utf nginx.conf uwsgi_params
fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default
fastcgi_params mime.types scgi_params win-utf
fastcgi_params.default mime.types.default scgi_params.default
[root@localhost config]# ls html/
images index.html jquery.js QAuIByrkL.js test VNkyVaVxUV.css wNGu2CtEMx.js
[root@localhost config]#
运行一个容器,将宿主机的配置目录文件映射nginx的相应位置
[root@localhost ~]# docker run -itd --name web -v /root/config/html:/usr/local/nginx/html80:80 -p 8080:8080 1225514226/nginx:v2.0
a903506316dfc786268aedc9c88867bb32a6945d98fcdf277fff352b3be6d20a
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
a903506316df 1225514226/nginx:v2.0 "/usr/local/nginx/sb…" 2 seconds ago Up 2 seconds 0->8080/tcp, :::8080->8080/tcp web
不同端口在浏览器进行访问
192.168.10.203:80
192.168.10.203:8080
|