原创 标题:  Centos 基于Docker的Nginx大发3d

Docker大发3d

环境要求

Docker支持CentOS 7 (64-bit)和CentOS 6.5 (64-bit) 或更高的版本。

Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。

Docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本。

查看内核命令:

uname -r

大发3dDocker

如果之前已经大发3d过Docker,则先移除旧版本。具体命令如下:

sudo yum remove docker
sudo yum remove docker-client
sudo yum remove docker-client-latest
sudo yum remove docker-common
sudo yum remove docker-latest
sudo yum remove docker-latest-logrotate
sudo yum remove docker-logrotate
sudo yum remove docker-selinux
sudo yum remove docker-engine-selinux
sudo yum remove docker-engine

大发3d依赖工具

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

添加软件源信息

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

更新 yum 缓存

sudo yum makecache fast

大发3d Docker-ce

sudo yum -y install docker-ce

启动 Docker 后台服务

sudo systemctl start docker

测试hello-world

docker run hello-world

由于本地没有hello-world这个镜像,所以会下载一个hello-world的镜像,并在容器内运行。

基于Docker的Linux大发3d

查询Docker Hub的Nginx镜像:

docker search nginx

执行结果:

[root@iZ2zeck5vyquf4xc1v0e4fZ nginx]# docker search nginx
NAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
nginx                                                  Official build of Nginx.                        9946                [OK]
jwilder/nginx-proxy                                    Automated Nginx reverse proxy for docker con…   1435                                    [OK]
richarvey/nginx-php-fpm                                Container running Nginx + PHP-FPM capable of…   627                                     [OK]
jrcs/letsencrypt-nginx-proxy-companion                 LetsEncrypt container to use with nginx as p…   425                                     [OK]
kong                                                   Open-source Microservice & API Management la…   235                 [OK]
webdevops/php-nginx                                    Nginx with PHP-FPM                              114                                     [OK]
kitematic/hello-world-nginx                            A light-weight nginx container that demonstr…   111
zabbix/zabbix-web-nginx-mysql                          Zabbix frontend based on Nginx web-server wi…   73                                      [OK]
bitnami/nginx                                          Bitnami nginx Docker Image                      58                                      [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5   ubuntu-16-nginx-php-phpmyadmin-mysql-5          48                                      [OK]
linuxserver/nginx                                      An Nginx container, brought to you by LinuxS…   42
tobi312/rpi-nginx                                      NGINX on Raspberry Pi / armhf                   23                                      [OK]
blacklabelops/nginx                                    Dockerized Nginx Reverse Proxy Server.          12                                      [OK]
wodby/drupal-nginx                                     Nginx for Drupal container image                11                                      [OK]
webdevops/nginx                                        Nginx container                                 8                                       [OK]
nginxdemos/hello                                       NGINX webserver that serves a simple page co…   8                                       [OK]
centos/nginx-18-centos7                                Platform for running nginx 1.8 or building n…   8
centos/nginx-112-centos7                               Platform for running nginx 1.12 or building …   5
1science/nginx                                         Nginx Docker images that include Consul Temp…   4                                       [OK]
behance/docker-nginx                                   Provides base OS, patches and stable nginx f…   3                                       [OK]
travix/nginx                                           NGinx reverse proxy                             2                                       [OK]
pebbletech/nginx-proxy                                 nginx-proxy sets up a container running ngin…   2                                       [OK]
toccoag/openshift-nginx                                Nginx reverse proxy for Nice running on same…   1                                       [OK]
mailu/nginx                                            Mailu nginx frontend                            1                                       [OK]
ansibleplaybookbundle/nginx-apb                        An APB to deploy NGINX                          0                                       [OK]

其中第一个为官方镜像,拉取name为nginx的镜像:

docker pull nginx

下载完成,查看本地镜像列表:

[root@iZ2zeck5vyquf4xc1v0e4fZ nginx]# docker images nginx
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              dbfc48660aeb        5 days ago          109MB

启动前准备工作

首先,启动Nginx需要配置nginx.conf文件,此文件可以在原有的Nginx配置中找到,也可以在官网下载压缩包,找到对应的nginx.conf、mime.types(nginx.conf中会用到)和conf.d文件目录(nginx.conf可配置加载此文件夹下的配置)。找到以上文件及文件夹之后,放到指定位置,比如:/root/nginx文件夹下。

启动命令

docker run -p 80:80 --name docker-nginx -v /root/nginx/:/etc/nginx/ -d nginx
  • -p 80:80:将容器的80端口映射到主机的80端口,第一个为容器80端口,第二个为主机80端口。
  • —name 指定docker的名称
  • -v 将当前主机的nginx目录挂载到容器的/etc/nginx目录下。其他需要挂载的可重复使用此参数。

完成docker的启动之后,执行docker ps可查看docker的运行情况:

[root@iZ2zeck5vyquf4xc1v0e4fZ ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
9cce31704b6d        nginx               "nginx -g 'daemon of…"   3 days ago          Up 41 seconds       0.0.0.0:80->80/tcp   docker-nginx

后续可按照nginx的政策使用方式进行操作。

END
朱智胜的个人博客-微信公众号