Docker-compose was used to build LNMP development environment
In the last episode we were able to set up the LNMP development environment using Docker, but you may have noticed that the configuration is quite complicated, and each container starts with a long command. Is there an easier way? Docker-compose: Docker-compose
What is Docker-compose?
Docker-compose is a tool written in Python for defining and running multiple containers.
The installation
Binary package installation
// For network reasons, you can download the file directly and put it in the corresponding location. Finally gives the corresponding execute permissions is the same $sudo curl -l https://github.com/docker/compose/releases/download/1.25.5/docker-compose- ` uname -s`-`uname -m` > /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
Copy the code
PIP install
$ sudo pip install -U docker-compose
Copy the code
The bash completion command
For docker-compose, use the following command: docker-compose (if it does not work, exit the terminal and enter again)
https://raw.githubusercontent.com/docker/compose/1.25.5/contrib/completion/bash/docker-compose > $curl - L /etc/bash_completion.d/docker-composeCopy the code
uninstall
Uninstallation through binary package installation
$ sudo rm /usr/local/bin/docker-compose
Copy the code
Uninstall via PIP installation
$ sudo pip uninstall docker-compose
Copy the code
Docker-compose configures the LNMP development environment
We will directly configure the LNMP environment configured in the last video by docker-compose
The main steps are as follows:
- Create a directory easy-Docker as docker-compose directory
- Run a temporary nginx container, copy the nginx configuration file to the Easy-Docker directory, and modify the configuration file
- Create a PHP directory in the easy-Docker directory and create a Dockerfile file in that directory
- Edit the Dockerfile file in PHPFPM
- Create a docker-comemage. yml file in the easy-Docker directory and edit it
- Run with docker-compose up -d
// Create a directory to hold the content required for the docker-compose project $mkdir easy-docker &&cd$docker run --name temp-nginx -d nginx $docker cp temp-nginx:/etc/nginx . / / / delete temporary nginx container $docker rm -f temp - nginx / / modify nginx configuration file (see below) $vim nginx/conf. D/default. Conf / / create a directory as nginx Container project home directory $mkdir wwwroot // create PHPFPM directory $mkdir PHPFPM &&cd$vim Dockerfile $vim Dockerfile $vim Dockerfile $vim docker-compose.yml $cd. $vim docker-compose. Yml // build an image and start the container $docker-compose up // test $echo "
">./wwwroot/info.php // access the page to see how the phpInfo page succeedsCopy the code
Nginx configuration file
PHPFPM Dockerfile content
FROM PHP :7.2-fpm RUN sed -i"s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list \
&& rm -Rf /var/lib/apt/lists/* \
&& apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-install -j$(nproc) iconv \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install mysqli pdo pdo_mysql
Copy the code
Docker-compose file contents
The docker-comemage. yml file above only shows the usage of some of the instructions, please refer to the link for details of other instructions.
Docker-compose common command
This command is very common and attempts to automate a series of operations including building an image, (re) creating a service, starting a service, and associating a service with a container.
$ docker-compose up -d
Copy the code
The container started by the up command will be stopped and the network removed
$ docker-compose down
Copy the code
For example, docker-compose ps, docker-compose exec, etc., you can try it by yourself. The related documents
Excellent Project Reference
Docker-compose: docker-compose: docker-compose: docker-compose: docker-compose: docker-compose: docker-compose: docker-compose: docker-compose So what’s the easy way?
Here I would like to recommend two good projects that I have used for your reference.
laradock
LNMP