关于Docker运行Nginx的文章层出不穷,鄙人推荐
http://www.runoob.com/docker/docker-install-nginx.html
<http://www.runoob.com/docker/docker-install-nginx.html>
这篇文章中介绍的两种方法。在这里,我着重介绍下第二种方法吧,直接从docker Hub上拉取Nginx镜像,供我们使用。
这里,我在虚拟机中安装了CentOS7,然后,安装docker,这一步,就不必详细介绍了。假设,你已经成功安装了docker。我这里安装的版本是1.13.1
,API版本1.26,Client: Version: 1.13.1 API version: 1.26 Package version: <unknown>
Go version: go1.8.3 Git commit: 774336d/1.13.1 Built: Wed Mar 7 17:06:16 2018
OS/Arch: linux/amd64Server: Version: 1.13.1 API version: 1.26 (minimum version
1.12) Package version: <unknown> Go version: go1.8.3 Git commit: 774336d/1.13.1
Built: Wed Mar 7 17:06:16 2018 OS/Arch: linux/amd64 Experimental: false
首先,创建一个目录:
mkdir -p ~/nginx/www ~/nginx/logs ~/nginx/conf
命令进入nginx目录。

然后,我们通过docker search命令,来检索nginx镜像
docker search nginx INDEX NAME DES CRIPTION STARS OFFICIAL AUTOMATED docker.io
docker.io/nginx Off icial build of Nginx. 8564 [OK] docker.io
docker.io/jwilder/nginx-proxy Aut omated Nginx reverse proxy for docker c...
1335 [OK] docker.io docker.io/richarvey/nginx-php-fpm Con tainer running Nginx
+ PHP-FPM capable ... 547 [OK] docker.io
docker.io/jrcs/letsencrypt-nginx-proxy-companion Let sEncrypt container touse
with nginx as... 368 [OK] docker.io docker.io/kong Ope n-source Microservice &
APIManagement ... 188 [OK] docker.io docker.io/webdevops/php-nginx Ngi nx with
PHP-FPM103 [OK] docker.io docker.io/kitematic/hello-world-nginx A l ight-weight
nginxcontainer that demons... 99 docker.io docker.io/bitnami/nginx Bit nami
nginx Docker Image52 [OK] docker.io docker.io/zabbix/zabbix-web-nginx-mysql Zab
bix frontend basedon Nginx web-server ... 51 [OK] docker.io docker.io/1
and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubu ntu-16
-nginx-php-phpmyadmin-mysql-5 35 [OK] docker.io docker.io/linuxserver/nginx An
Nginxcontainer, brought to you by Linu... 35 docker.io
docker.io/tobi312/rpi-nginx NGI NXon Raspberry Pi / armhf 19 [OK] docker.io
docker.io/nginxdemos/nginx-ingress NGI NX Ingress Controllerfor Kubernetes . ...
11 docker.io docker.io/blacklabelops/nginx Doc kerized Nginx Reverse Proxy
Server.9 [OK] docker.io docker.io/wodby/drupal-nginx Ngi nx for Drupal container
image9 [OK] docker.io docker.io/webdevops/nginx Ngi nx container 8 [OK]
docker.io docker.io/centos/nginx-18-centos7 Pla tform for running nginx 1.8 or
building...6 docker.io docker.io/nginxdemos/hello NGI NX webserver that serves
a simple page ...6 [OK] docker.io docker.io/1science/nginx Ngi nx Docker images
thatinclude Consul Te... 4 [OK] docker.io docker.io/centos/nginx-112-centos7
Pla tformfor running nginx 1.12 or buildin... 3 docker.io
docker.io/behance/docker-nginx Pro vides base OS, patchesand stable nginx... 2
[OK] docker.io docker.io/pebbletech/nginx-proxy ngi nx-proxysets up a container
running ng...2 [OK] docker.io docker.io/toccoag/openshift-nginx Ngi nx reverse
proxyfor Nice running on sa... 1 [OK] docker.io docker.io/travix/nginx NGi nx
reverse proxy 1 [OK] docker.io docker.io/mailu/nginx Mai
然后,通过docker pull命令,从远程拉取nginx镜像,命令如下:
docker pull nginx
拉取成功后,我们可以通过docker images命令,查看镜像:
[root@localhost nginx]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/nginx latest ae513a47849c4 weeks ago 109 MB
然后,通过docker run命令启动容器,运行镜像:
[root@localhost nginx]# docker run -p 80:80 --name mynginx -v $PWD/www:/www -v
$PWD/conf/nginx.conf:/etc/nginx/nginx.conf --privileged=true -v
$PWD/logs:/www/logs -v $PWD/html:/etc/nginx/html -d nginx
这里,-v $PWD/www:/www把主机当前目录下的www目录绑定到了docker中www目录。需要注意的是,

由于docker容器需要对nginx.conf的访问权限,因此,绑定nginx.conf文件时,后面添加--privileged=true命令。

通过docker ps命令,查看容器运行状况

原文链接 <https://yq.aliyun.com/articles/598410?utm_content=m_51307>

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信