In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
I. brief introduction
The Compose project is the official open source project of Docker, which is responsible for the rapid orchestration of Docker container clusters.
From the previous introduction, we know that using a Dockerfile template file makes it easy for users to define a separate application container. However, in daily work, we often encounter situations that require multiple containers to cooperate with each other to complete a task. For example, to implement a Web project, in addition to the Web service container itself, you often need to add a back-end database service container, or even a load balancing container.
Compose happens to meet such needs. It allows users to define a set of associated application containers as a project (project) through a separate docker-compose.yml template file (YAML format).
There are two important concepts in Compose:
Service (service): a container for an application that can actually include several container instances running the same image.
Project (project): a complete business unit consisting of a set of associated application containers, defined in the docker-compose.yml file.
The default management object of Compose is the project, and the life cycle of a set of containers in the project can be easily managed through subcommands.
A system using a micro-service architecture generally consists of several micro-services, and each micro-service generally deploys multiple instances. If each service has to be started and stopped manually, it will be inefficient and have a large amount of maintenance.
II. Introduction to Docker Compose
Through Docker-Compose, users can easily define a multi-container application with a configuration file, and then use a single instruction to install all the dependencies of the application. Docker-Compose solves the problem of how to manage orchestration between containers.
Docker Compose working schematic diagram
There are two important concepts in writing:
Service (service): a container for an application can actually include multiple container instances running the same.
Project (project): a complete business unit consisting of associated application containers, defined in the docker-compose.yml file.
A project can be associated by multiple services (containers) to form a project-oriented management, and the life cycle of a single container in the project can be easily managed through subcommands.
The Compose project is written by Python and the implementation invokes the API provided by the Docker service to manage the container. Therefore, as long as the operating platform supports Docker API, Compose can be used for orchestration management on it.
The three choreography tools of Docker:
Docker Compose: a tool for assembling multi-container applications that can be deployed in Swarm clusters.
Docker Machine: is a tool that supports multi-platform installation of Docker, using Docker. Machine, you can easily install Docker in laptops, cloud platforms, and data centers.
Docker Swarm: a container cluster management tool natively provided by the Docker community.
Detailed explanation of Docker Compose command
The use of Docker compose is very similar to the use of the docker command, but it is important to note that most compose commands need to be executed in the same directory as the docker-compose.yml file.
Compose runs in daemon mode with the-d option
3. Docker Compose installation # download sudo curl-L https://github.com/docker/compose/releases/download/1.20.0/docker-compose-`uname-s`-`uname-m`-o / usr/local/bin/docker-compose# install chmod + x / usr/local/bin/docker-compose# view version docker-compose version IV, experimental environment host ip address service docker192.168.1.11compose+wordpress five docker three Musketeers docker-compose
Orchestration tool for docker containers: solves the management of multiple containers that depend on each other.
[root@docker01 ~] # docker-compose-docker-compose / verify that there is an existing command
Configuration file instance of docker-compose
Manage the container by identifying a docker-compose.yml configuration file.
Set the number of spaces for the tab key [root@docker01 ~] # vim .vimrcset tabstop=2// set the number of spaces for the tab key [root@docker01 ~] # source .vimrc / / refresh create a docker-compose.yml test file [root@docker01 ~] # mkdir compose_test// create a test directory [root@docker01 ~] # cd compose_test/ [root @ docker01 compose_test] # vim docker-compose.yml// create a test file docker-compose.ymlversion: Interpretation of "3" services: nginx: container_name: web-nginx image: nginx restart: always ports:-90:80 volumes: -. / webserver:/usr/share/nginx/htmldocker-compose.yml file
The first part: version: specifies the version of the syntax format.
Part 2: service: define the service, (what kind of container do you want to run)
Run the container specified by docker-compose through the docker-compose.yml file [run] () Container [root@docker01 compose_test] # docker-compose up-dash / background. (in the current directory where this command is executed, a configuration file for docker-compose.yml is also required, and there is usually only one. )
[root@docker01 compose_test] # docker ps// View Container Information
[root@docker01 compose_test] # curl 127.0.0.1 nginx / nginx access will fail because there is no page content in the mount directory
[root@docker01 compose_test] # vim webserver/index.html// to create a test web page xgp666 [root@docker01 compose_test] # curl 127.0.0.1 xgp666 / visit again, it is a successful xgp666
Through the docker-compose.yml file [stop running] () Container [root@docker01 compose_test] # docker-compose stop
Through the docker-compose.yml file [restart] () Container [root@docker01 compose_test] # docker-compose restart
Not in the same directory as the docker-compose.yml file, use [- f] () to specify the directory [root@docker01 ~] # docker-compose-f compose_test/docker-compose.yml stop and, in the process of running container (docker-compose.yml) It also supports Dockerfile [root@docker01 compose_test] # vim Dockerfile// to write dockerfileFROM nginxADD webserver / usr/share/nginx/html [root@docker01 compose_test] # vim docker-compose.yml / / modify the docker-compose.yml file version: "3" services: nginx: build:. # add container_name: web-nginx image: new-nginx:v1.0 # modify the image name restart: always ports:-90:80 through the docker-compose.yml file [stop and delete] () Container [root@docker01 compose_test] # docker-compose stopStopping web-nginx... Done [root@docker01 compose_test] # docker-compose rm View Container Information via docker-compose.yml File [run] () Container [root@docker01 compose_test] # docker-compose up-docker-compose up / docker-compose.yml File [run] () Container [root@docker01 compose_test] # Container
Test nginx access page [root@docker01 compose_test] # curl 127.0.0.1 nginx page / test access nginx page, successfully xgp666
VI. Build wordpress blog download wordpress and mysql:5.7 container [root@docker01 ~] # docker pull wordpress// download wordpress container [root@docker01 ~] # docker pull mysql:5.7// download mysql:5.7 container write a docker-ccompose.yml [root@docker01 ~] # mkdir wordpress// create wordpress test file [root@docker01 ~] # cd wordpress/ [root@docker01 wordpress] # vim docker-compose.yml// write docker-compose.ymlversion: "3.1" services: wordpress: image: wordpress restart: always ports:-8080 always ports 80 environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: 123.com WORDPRESS_DB_NAME: wordpress db: image: mysql:5.7 restart: always environment: MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: 123.com MYSQL_ROOT_PASSWORD : 123.com through docker-compose.yml file [run] () Container [root@docker01 wordpress] # docker-compose up-d
[root@docker01 wordpress] # docker ps// View Container Information
[root@docker01 wordpress] # docker logs container name / / View container log browser to visit http://192.168.1.11:8080/
Select language
Install wordpress
Log in to wordpress
After you have successfully logged in, you can make your own settings.
Troubleshooting
First check to see if the hostname has changed
Whether the firewall and selinux are turned off
Permission is given to the installation of the docker-compose command
Is there a problem with docker--compose.yml writing?
Whether the container executes normally
(if the browser cannot access it, you can add a route forwarding)
Other wordpress optimization recommendations
After the above steps, even if the basic wordpress construction and some necessary settings are completed, the rest are more personal choices, and each person may have different requirements. Here are some suggestions for wordpress optimization.
1. Whether you are doing Baidu seo, install a SEO plug-in, even if you do not want to set the TDK of the article, at least it is necessary to set it on the home page of the website. All in one seo pack is recommended.
two。 Regular backup, the importance of backup needless to say, those who have lost data will form the habit of backup, WordPress backup website method
3. Install a security plug-in, recommended by the WordPress security plug-in
4. Update the theme and plug-in of the website in time, and the automatic update method of WordPress plug-in
5. Delete all useless themes and plug-ins, WordPress delete theme method
6. Set up spam filtering, wordpress anti-spam plug-in Akismet
WordPress site is mainly based on these, the following is based on their own site for a variety of settings, different types of sites use themes and plug-ins are very different. However, if you can learn what is introduced in this article, I believe your site has exceeded most of the websites. All right, that's all for today's tutorial. If you have any questions or other better suggestions, please feel free to leave a comment for discussion.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.