Before Windows has been using vagrant to do development, the team is also a variety of development environment, several people do not have a unified environment, a variety of on-line are human flesh, and occasionally because of development, testing, production environment due to software version or inconsistent configuration problems, this year, ready to continue to play docker+ Agile development Models under kubernetes (and of course, others: continuous integration)
The first step, environment construction
Docker build LNMP Environment + Redis + Elasticsearch under Mac
Pull Image Nginx
Docker Pull Hub.c.163.com/library/nginx:latest
Pull image MySQL
Docker Pull hub.c.163.com/library/mysql:5.6
Pull image php
Docker Pull HUB.C.163.COM/LIBRARY/PHP:7.1-FPM
Create a MySQL container
Docker run-d-P 3306:3306-e mysql_root_password=123456--name liugx_mysql56 hub.c.163.com/library/mysql:5.6
Parameter description
-D Let the container run in the background
-P adding host-to-container port mappings
-e Set the environment variable, here is the initial password to set the root user of MySQL, this must be set
–name the name of the container, whatever it takes, but must be unique
Create a PHP-FPM container
Docker run-d-v/users/liugx/docker/data/www:/var/www/html-p 9000:9000--link liugx_mysql56:mysql--name liugx_php71 hu b.c.163.com/library/php:7.1-fpm
Parameter description
-D Let the container run in the background
-P adding host-to-container port mappings
-V Adds a directory map, that is, the/users/liugx/docker/data/www on the host and the/var/www/html directory in the container is synchronous
The name of the –name container
–link is linked to another container so that we can use the service in the other container in the current container.
Here if you do not specify the –link parameter is actually available, because the easy itself is also IP and unique, so we can also directly use IP to access the container.
Creating an Nginx Container
Docker run-d-P 80:80--name liugx_nginx-v/users/liugx/docker/data/www:/var/www/html--link liugx_php71:phpfpm hub.c.1 63.com/library/nginx
Parameter description:
-D Let the container run in the background
-P adding host-to-container port mappings
-V Adds a directory map, that is, the/users/liugx/docker/data/www on the host and the/var/www/html directory in the container is synchronous
The name of the –name container
–link in connection with another container
The following Redis and Elasticsearch are directly like creating a MySQL database Container
Docker Pull Hub.c.163.com/library/redis:latest
Docker Pull Hub.c.163.com/library/elasticsearch:latest
##### #注意 ######
After configuration, you need to modify the Nginx configuration file (The following steps are similar to normal configuration, modify the configuration of the corresponding Nginx container to take effect)
Modify the main content, modify the root directory of the host, if the. php file is forwarded to the backend PHP-FPM processing (192.168.99.100:9000)
Method:
Modify Nginx configuration file (Enter container):
Docker exec-it Liugx_nginx Bash
Update the software source
APT Update
Install Vim
Apt-get Install Vim
Attach stickers:
Connect to MySQL
accessing PHP files
Nginx Configuration
Docker build LNMP Environment + Redis + Elasticsearch under Mac