LNMP Docker – Faster build images for domestic environments

L(Alpine Linux) + N(Nginx) + M(MariaDB) + P(PHP) Docker container application environment.

Container Upgrade Logs

More upgrade: https://github.com/bravist/lnmp-docker/releases

2017-07-14

  • Establish the container virtual network, asNginx WebThe container is configured with static IP and optimizednginxCommunication rules between virtual hosts.
  • newMongoDBContainer that supports NoSQL databases.

2017-06-19

  • newphp-crondPeriodic task container service, adoptedcrontabCommand implementation, support host arbitrary add timing script (PS:cp default.example default)

PHP Upgrade Log

The main features

  • With the larger VERSION of PHP7, more PHP7 extensions are installed with the Alpine Linux extension repository.

  • Build different base images based on Alpine Linux and Debian. The Master branch is based on Ali-OSM acceleration and can quickly build container clusters in 5 minutes in a domestic environment. The Alpine Branch is based on the Alpine Linux official image and is suitable for non-domestic environments. The Debian branch is based on the official Debian base image of Docker, and the overall image size is relatively large.

  • Build a clean, lightweight PHP dependency environment, install common PHP extensions and Composer, support PHP CLI and PHP FPM mode. PHP CLI is suitable for command line interaction projects, PHP FPM with Nginx, build PHP Web application environment. In addition, THE PHP FPM image is based on the PHP CLI basic image, minimizes the PHP container image, efficient use of resources.

  • Docker Hub official website retains PHP basic images of different Linux versions and geographical environments. In order to improve the speed of Docker image construction in China, PHP container construction is completed quickly based on Alibaba open source image service -Ali-OSM Alpine. For non-domestic environments, it is recommended to clone the Alpine branch for fast build, as well as try the Debain branch.

  • Provides PHP CLI mode independent running containers: call-Websockt and php-superviosr. Call-websockt runs the WORKman-based PHP Socket service. Php-supervior implements supervisor-based queue services.

  • Separate container runtime files, container run logs, and data from the host to facilitate debugging and rebuilding of the container.

  • Support Nginx virtual site, SSL certificate service. For configuration, refer to the cert and conf.d directory files in Nginx.

  • Support the program communication between multiple virtual sites. Refer here to learn about communication issues between multiple projects.

  • Docker Compose Compose container to support rapid server setup tasks in development, test and production environments.

Installed LNMP Docker

Project depend on

  • CentOS 7
  • Docker 1.12 (Docker requires a 64-bit system with a kernel version of at least 3.10)
  • Docker Compose

Install the Docker

Docker installation in different platforms, different geographical environments, different operating systems in the way is not the same, here is still recommended to use the official CentOS installation method, other methods please search by yourself, in addition, especially recommended to use Ali Cloud provided Docker Hub image site, to provide you with exclusive Docker acceleration services.

Ali Cloud ECS installation Docker

$ sudo yum install -y yum-utils

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

$ sudo yum makecache fast

$ sudo yum -y install docker-ce

# Add docker group
$ sudo groupadd docker

# Add user to docker group
$ sudo usermod -aG docker $USER

## start up docker
$ sudo systemctl enable docker

$ sudo systemctl start docker
Copy the code

Ali Cloud Docker Hub image site acceleration

Ali Cloud Docker Hub accelerator, you need to open ali Cloud account, each account has its own acceleration address.

$ sudo mkdir -p /etc/docker
$ sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://muehonsf.mirror.aliyuncs.com"]
}
EOF
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

Copy the code

Install the Docker Compose

Docker Compose official Gtihub repository installation method is recommended, please select a version first.

https://github.com/docker/compose/releases/download/1.13.0/docker-compose- $curl - L ` uname-s`-`uname -m` > /usr/local/bin/docker-compose

$ chmod +x /usr/local/bin/docker-compose
Copy the code

Installed LNMP Docker

  1. Clone project Git repository, non-domestic users please switch to alpine branch after cloning.

    $ git clone https://github.com/bravist/lnmp-docker
    Copy the code

    If git is not installed, download the source code package to install it.

  2. Copy the.env.example file and configure the project environment variables. Note that after the container is successfully run, you need to modify the. Env file again to ensure the program communication between multiple projects.

    # generate. Env file
    $ cd lnmp-docker
    $ cp .env.example .env
    
    Generate crON configuration
    $ cd php-crond/crontabs/
    $ cp default.example default
    Copy the code
  3. Build a container cluster.

    $ docker-compose build && docker-compose up -d
    Copy the code
  4. Wait about 5 minutes and check whether the container is complete. If you encounter problems, please feel free to post your issue.

    ➜  ~ docker ps
    CONTAINER ID        IMAGE                                   COMMAND                  CREATED             STATUS              PORTS                                                               NAMES
    f4452c868dcc        lnmpdocker_nginx                        "nginx -g 'daemon off"2 hours ago Up 2 hours 0.0.0.0:80->80/ TCP, 0.0.0.0:443->443/ TCP lnmp-nginx 15182399966b lnmpDocker_php-supervisor"supervisord --nodaem"2 hours ago Up 2 hours lnmp-php-supervisor A68c55C28995 Bravist/PHP-Fpm - Alpine aliyun-app:1.5"/usr/sbin/php-fpm7 -"2 hours ago Up 2 hours 0.0.0.0:9000->9000/ TCP lnmp-php-fpm eff86b31f2ba lnmpDocker_call-websocket"/usr/bin/php /usr/sh"2 hours ago Up 2 hours 0.0.0.0:8190-8191->8190-8191/ TCP lnmp-call-websocket bd3Cecff945e mariadb"docker-entrypoint.sh"2 hours ago Up 2 hours 0.0.0.0:3306->3306/ TCP lnmp-mariadb 279b2f995b2a lnmpdocker_redis"docker-entrypoint.sh"2 hours ago Up 2 hours 0.0.0.0:6379->6379/ TCP lnmp-redisCopy the code

  5. Modify the DOCKER_HOST_IP configuration parameter in the configuration file, here first through the docker inspect query nginx container obtain.

    $ docker inspect lnmp-nginx | grep IPAddress
                "SecondaryIPAddresses": null,
                "IPAddress": ""."IPAddress": "192.168.32.7", $ vi .env ... DOCKER_HOST_IP = 192.168.32.7... :wq $ docker-compose build && docker-compose up-d
    Copy the code

maintenance

In the construction process, if there is a problem, please issue the issue as soon as possible. Special tips are given here:

  • During the construction process, there are two types of acceleration services. The exclusive image acceleration provided by Ali Cloud is used to quickly pull remote images from the Docker Hub warehouse, while Ali-OSM is used to quickly download software packages in the process of container image construction.

  • During the new installation and debugging, try to clean up the existing local Docker containers and images before trying again.

    View all containers that are running and exiting
    $ docker ps -a
    
    # delete stopped containers
    $ docker rm -f contianer_name ...
    
    # Quickly stop and delete container clusters
    $ docker-compose down
    
    Delete the local Docker image
    $ docker rmi -f image_name ....
    Copy the code
  • You need to log in using sh shell to enter containers, because all containers are based on Alpine Linux and use sh shell by default.

    $ docker exec -it lnmp-nginx sh
    Copy the code

Use cTOP to query resources occupied by containers

Ctop can be used to query the resource occupation of containers. It is recommended to install cTOP, such as the usage of Gitlab and LNMP Docker on our server:

$CTOP cTOP-15:36:35 CST 10 Containers NAME CID CPU MEM NET RX/TX IO R/W PIDS ◉ gitlabdocker_gitlab_1 97D5ba4B4918 5% 1.99g / 7.64g 948M / 1.6g 120M / 776K 0 ◉ gitlabdocker_postgresQL_1 146b662e4d62 0% 75M / 7.64g 897K / 8M 24M / 0B 0 ◉ Gitlabdocker_redis_1 3bcf1582f892 2% 14M / 7.64g 1.6g / 940M 5M / 0B 0 ◉ lnmp-call-websocket EFF86b31f2ba 0% 66M / 7.64g 3K / 648B 20M / 0B 0 ◉ lnmp-Mariadb bd3CECFF945e 0% 179M / 7.64g 90K / 276K 27M / 0B 0 ◉ lnmp-nginx f4452C868dcc 0% 8M / 7.64g 14M / 5M 5M / 0B 0 ◉ lnmp-php-fpm a68c55c289950% 72M / 7.64g 1M / 13M 20M / 0B 0 ◉ lnmp-php-supervisor 15182399966b 1% 1.8g / 7.64g 92M / 145M 26M / 0B 0 ◉ lnmp-redis 279b2f995b2a 0% 8M / 7.64g 62M / 16M 2M / 0B 0 ◉ lnmp-www 09c684094c18 - - - - -Copy the code

View the container image size

$Docker Images REPOSITORY TAG IMAGE ID CREATED SIZE lnmpDocker_nginx latest 8ed67b3D522c 2 hours ago 15.5 MB Lnmpdocker_php-supervisor latest 28d1689EC35b 2 hours ago 160.4 MB lnmpDocker_redis latest 61CEDd081DD7 2 hours ago 12.63 MB lnmpDocker_call-webSocket latest 47883e0cc4cdDocker. IO /bravist/php-fpm-alpine-aliyun-app 1.1c98507f2de3 2 hours ago 117.9 MB docker. IO /bravist/ php-fpm-Alpine-aliyun-app 1.1c98507f2de3 2 hours ago 117.9 MB IO /bravist/ PHP -cli-alpine aliyun-app 1.3 505a11124094 24 hours ago 117.9 MB Docker. IO /redis 3.0-alpine IO /mariadb latest ea0322bb4096 9 days ago 395.1 MB docker. IO /nginx 1.13.1- Alpine 7EBd6770d0d6 10 days ago 15.49 MBCopy the code

reference

Docker — From getting started to practice

— github.com/bravist/lnm…