Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The methods and steps of using docker to build web Service Environment

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Preface

People who have done development should not be too familiar with the installation and configuration of the development environment, no matter what you do, they will have a certain dependence on the development environment. For PHP Web development, the development environment must have at least one Web server (such as Apache, Nginx), a database server (such as MySQL) and a PHP parser, if your PHP code uses some extensions, then you also need to install these extensions to your PHP so that your PHP code can run smoothly. For a developer who just wants to tap the code quietly, the installation and configuration of the development environment can be troublesome just once. However, things often can not be done according to people's wishes, you can not guarantee that the system will be reinstalled, there is no guarantee that there will be a new environment. In short, you will occasionally need to reinstall and configure your development environment!

You can recall how long it took to install and configure your development environment last time, and did you remember that the PHP extension you needed was not installed until you ran the Times wrong? Fortunately, since I had Docker, my mother no longer has to worry about my development environment. With Docker, the development environment only needs to be installed and configured once, and then it is easy to build the same development environment with only one command!

This is the purpose of this article, to introduce the service environment for installing and configuring Web under Docker, and to realize the functions of once installation and configuration, multiple reuse and cross-platform reuse.

Overview of Docker

What is Docker? You can think of Docker as a container for a packaged environment. It can package the environment into an image, and then create a container based on that image when needed, so that the required environment comes back. Just mentioned the two core concepts of Docker, mirroring and container.

The Docker image is an application made in accordance with the rules of Docker for special purposes, somewhat similar to the installation package in Win-dows. Containers are created based on an image, and several containers with different names but the same function can be created based on one image. The mirror is static and the container is dynamic.

In addition to mirroring and containers, there are two other concepts to understand, namely, repository and docker-compose. The Docker repository is where the images are stored. We can pull the images from the Docker repository to the local location, and then create containers based on the images. Docker-compose manages containers. The idea of Docker is that a container does only one thing, and multiple containers may be used in a development environment, such as PHP, Nginx, MySQL, and so on, in a Web service environment. Then a Web service environment needs to have three containers, and there are dependencies between these containers, Nginx depends on PHP,PHP depends on MySQL. With docker-compose, you can manage these containers very well, it can determine the startup order and closing order of each container according to the dependencies between containers, manage the port mapping relationship between containers and host machines, and configure the data sharing policy between containers and host machines, and so on.

Domestic image repositories

Due to the geographical location, it is relatively slow to visit the official warehouse of Docker, so here we introduce a domestic Docker warehouse: Lingqueyun. Lingque Cloud Image Warehouse brings together a large number of high-quality works from the community, allowing users to combine and reuse container-based micro-services, and easily build a new generation of cloud applications.

Build Web service environment

The focus of this article is to use Docker to build a Web service environment. If you don't have Docker installed in your environment, you can refer to here to install it yourself.

After installing Docker, it is easy to build a Web service environment, just one file and one command!

One file: docker-compose.yml

Nginx: image: index.alauda.cn/library/nginx links:-phpfpm ports:-"80:80"-"443 phpfpm ports" volumes:-/ Users/chenishr/www:/usr/share/nginx/html -. / nginx.conf:/etc/nginx/nginx.conf -. / nginx.d:/etc/nginx/conf.dmysql: image: index.alauda.cn/library/mysql environment: MYSQL_ROOT_PASSWORD: qazasdedc123 ports:-"3306 Suzhou 3306" phpfpm : image: index.alauda.cn/library/php:7.0-fpm links:-mysql volumes:-/ Users/chenishr/www:/var/www/html ports:-"9000 Users/chenishr/www:/var/www/html ports"

The content of the file above is simple. It defines three containers, nginx, mysql, and phpfpm. Each container definition contains some information, which is briefly introduced here.

Image: this field indicates that the container is based on that image to create the links: indicates that other containers need to be accessed inside the container. The name behaves like a domain name inside the container. It binds the IPports of the corresponding container: map the port inside the container to the host machine volumes: configure the shared files or directories between the container and the host machine.

An order.

With the above docker-compose.yml file, you only need one command to start all the containers, that is, to build the entire Web service environment!

Docker-compose up-d

Last

With Docker, setting up an environment has never been easier.

This article only introduces the most basic application of Docker, it also has many uses and is not limited to this article. It allows multiple versions of software to work at the same time. For example, I can use PHP7 and PHP5 on the same computer without confusion. Of course, there are others...

All right, that's all of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. If you have any questions, you can leave a message and exchange. Thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report