Three Musketeers docker docker-compose and build a wordpress blog

I. Introduction

Docker Compose official project is open source project, responsible for fast layout of Docker container cluster.

By the previous introduction, we know Dockerfile use a template file, allowing users to easily define a single application container. However, in their daily work, often encounter case to complete a task requiring multiple containers with each other. For example, to implement a Web project, in addition to Web services container itself, often also need to add the back-end database services container, even including load balancing containers.

Compose just to meet this demand. It allows the user to define a set of associated container application through a single docker-compose.yml template file (YAML format) for a project (project).

Compose There are two important concepts:

Service (service): a container application, the container may include several instances actually running the same image.
Project (project): a unit represented by a complete set of service associated with the application container composed of docker-compose.yml definition file.
The default management object Compose a project, the project of a group of containers easy life cycle management through sub-commands.

Micro System service architecture typically comprises a plurality of micro-services, each micro deploy multiple instances of the service ships. If you have to manually start and stop each service, so low efficiency, maintenance of large.

Two, Docker Compose introduction

You can easily define a multi-use container with a profile by Docker-Compose user, then all the dependencies, an instruction to complete the preparation of the installation of this application. Docker-Compose how to solve the problem between the container and container management choreography.

Docker Compose operating principle
Three Musketeers docker docker-compose and build a wordpress blog
writing there are two important concepts:

(Service): a container application, the container may actually comprise a plurality of identical instances of the same operation.
(Project): a complete business units associated with the respective container by the application of a composition defined in docker-compose.yml file.
A plurality of service items may be made (containers) associated composition for the project management, project in a single container easily lifecycle management subcommand.

Compose project written by Python, calling the API Docker services provided on implementation to manage the container. Therefore, as long as the operating platform to support Docker API, you can manage to orchestrate use Compose thereon.

Docker three layout tools:

Docker Compose: a tool used to assemble multi-vessel applications, distributed applications can be deployed in a cluster Swarm.

Docker Machine: support multi-platform installation tool Docker, the use of Docker. Machine, can be easily installed in the notebook Docker, cloud platform and data centers.

Docker Swarm: Docker is a container cluster management tools provided by the native community.

Docker Compose command Detailed

Use Docker compose very similar to using a docker command, but should be noted that most of the commands needed to compose the directory where the file docker-compose.yml to perform.
compose in daemon mode plus the -d option

Three, Docker Compose installation

#下载
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
#安装
chmod +x /usr/local/bin/docker-compose
#查看版本
docker-compose version

Fourth, the experimental environment

Host computer ip address service
docker 192.168.1.11 compose+wordpress

Five docker docker-compose Three Musketeers

docker container orchestration tools: managing multiple containers have to resolve mutual dependencies.

[root@docker01 ~]# docker-compose -v
//验证已有docker-compose命令

Three Musketeers docker docker-compose and build a wordpress blog

docker-compose profile Examples

By identifying a docker-compose.yml profile, to manage the container.

Set the number of spaces a tab

[root@docker01 ~]# vim .vimrc
set tabstop=2
//设置tab键的空格数量
[root@docker01 ~]# source .vimrc 
//刷新一下

Create a docker-compose.yml test files

[root@docker01 ~]# mkdir compose_test
//创建测试目录
[root@docker01 ~]# cd compose_test/
[root@docker01 compose_test]# vim docker-compose.yml
//创建测试文件docker-compose.yml
version: "3"
services:
  nginx:
    container_name: web-nginx
    image: nginx
    restart: always
    ports:
      - 90:80
    volumes:
      - ./webserver:/usr/share/nginx/html

Explain docker-compose.yml file

The first part: version: syntax of the specified version.

The second part: service: the definition of service, (what kind of container you want to run)

By docker-compose.yml file [operation] () of the container

[root@docker01 compose_test]# docker-compose up -d
//后台运行docker-compose规定的容器。(在执行这条命令的当前目录下,也需要一个docker-compose.yml的配置文件,并且通常只有一个。)

Three Musketeers docker docker-compose and build a wordpress blog

[root@docker01 compose_test]# docker ps
//查看容器信息

Three Musketeers docker docker-compose and build a wordpress blog

[root@docker01 compose_test]# curl 127.0.0.1:90
//访问nginx会失败,因为挂载目录没有页面内容

Three Musketeers docker docker-compose and build a wordpress blog

[root@docker01 compose_test]# vim webserver/index.html
//创建测试网页
xgp666
[root@docker01 compose_test]# curl 127.0.0.1:90
//再次访问,是成功的
xgp666

Three Musketeers docker docker-compose and build a wordpress blog

By docker-compose.yml file [stopped] () of the container

[root@docker01 compose_test]# docker-compose stop

Three Musketeers docker docker-compose and build a wordpress blog

By docker-compose.yml file [Restart] () of the container

[root@docker01 compose_test]# docker-compose restart

Three Musketeers docker docker-compose and build a wordpress blog

Not docker-compose.yml file directory, use the [-f] () the specified directory

[root@docker01 ~]# docker-compose -f compose_test/docker-compose.yml  stop

And, during operation container (docker-compose.yml), the supports Dockerfile

[root@docker01 compose_test]# vim Dockerfile
//编写dockerfile
FROM nginx
ADD webserver /usr/share/nginx/html 
[root@docker01 compose_test]# vim docker-compose.yml 
//修改docker-compose.yml文件
version: "3"
services:
  nginx:
    build: .     #添加
    container_name: web-nginx
    image: new-nginx:v1.0   #修改镜像名称
    restart: always
    ports:
      - 90:80

By docker-compose.yml file [stop and delete] () container

[root@docker01 compose_test]# docker-compose stop
Stopping web-nginx ... done
[root@docker01 compose_test]# docker-compose rm

By docker-compose.yml file [operation] () of the container

[root@docker01 compose_test]# docker-compose up -d
//通过docker-compose.yml文件[运行]()容器
[root@docker01 compose_test]# docker ps
//查看容器信息

Three Musketeers docker docker-compose and build a wordpress blog

Nginx access test page

[root@docker01 compose_test]# curl 127.0.0.1:90
//测试访问nginx页面,成功
xgp666

Three Musketeers docker docker-compose and build a wordpress blog

Sixth, build a wordpress blog

Download and wordpress mysql: 5.7 container

[root@docker01 ~]# docker pull wordpress
//下载wordpress容器
[root@docker01 ~]# docker pull mysql:5.7
//下载mysql:5.7容器

Write a docker-ccompose.yml

[root@docker01 ~]# mkdir wordpress
//创建wordpress测试文件
[root@docker01 ~]# cd wordpress/

[root@docker01 wordpress]# vim docker-compose.yml
//编写docker-compose.yml
version: "3.1"
services:
  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080: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

By docker-compose.yml file [operation] () of the container

[root@docker01 wordpress]# docker-compose up -d

Three Musketeers docker docker-compose and build a wordpress blog

[root@docker01 wordpress]# docker ps
//查看容器信息

Three Musketeers docker docker-compose and build a wordpress blog

[root@docker01 wordpress]# docker logs  容器名称
//查看容器日志

Browser to access it http://192.168.1.11:8080/

Choose a language

Three Musketeers docker docker-compose and build a wordpress blog

Install wordpress

Three Musketeers docker docker-compose and build a wordpress blog

Three Musketeers docker docker-compose and build a wordpress blog

Wordpress login

Three Musketeers docker docker-compose and build a wordpress blog

Three Musketeers docker docker-compose and build a wordpress blog

After the successful landing, and that it can be set up

Troubleshooting

First check whether the host name change
firewall and selinux is turned off
docker-compose the command is given permission to install
docker - compose.yml written question whether there is
container execution is normal
(if the browser can not access, you can add a route forwarding)

Other optimization tips wordpress

After the above steps, and some of the basic wordpress to build the necessary settings even completed, and the rest is more of a personal choice that each person may require different, say the following points wordpress optimization recommendations

1. Whether you are doing Baidu seo, install an SEO plugin, even if do not want to set the article TDK, there is at least necessary to set about the site's home page, it is recommended in One SEO Pack All
2. regular backups, backup importance Needless to say, any Diuguo people will develop the habit of data backup, WordPress website backup method
3. install a security plug-in, WordPress security plugins recommended
4. update the site's themes and plugins, WordPress plug-in automatically update method
5. delete all useless topics and plug-ins, WordPress theme delete method
6. set up spam filtering, wordpress plugin Akismet anti-spam

WordPress is the main base station, behind the words is to be set up according to their various sites, sites use different types of themes and plug-ins are very different. But if you can learn to content Benpian described, I believe that your site has exceeded most of the site, a good tutorial on here today, if you have any questions or other better suggestions are welcome to discuss the message

Guess you like

Origin blog.51cto.com/14320361/2460980