Recently the classmate bought a virtual machine (CENtos7 system), a domain name, let help build a personal blog. In line with simple and quick, personal blog uses wordpress to build. In order to facilitate the migration of blog system, use Docker to install wordpress. The following is the detailed process of the blog construction.

Update centos

yum -y update
Copy the code

Install docker

yum install docker
Copy the code

Start docker: systemctl start docker

Systemctl enable docker

Docker-compose installation

Docker-compose is a simple and effective tool for deploying multiple containers. Because wordpress and mysql containers need to be installed to build the blog system, docker-compose is used for deploying. Docker-compose can be installed in a different way, here the PIP installation is used.

1. Install python-pip

yum -y install epel-release
yum -y install python-pip
Copy the code

2. Upgrade PIP

pip install --upgrade pip
Copy the code

Check whether the installation is successful: PIP -v

Docker-compose install docker-compose

pip install docker-compose
Copy the code

Error:

It is a distutils installed project and thus we Cannot accurately determine which files belong to it which would lead to only a partial uninstall.Copy the code

Processing:

pip install docker-compose --ignore-installed requests
Copy the code

Docker-compose script docker-comemage. yml

version: '3.3'

services:
  db:
    image: Mysql: 5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: wordpress123
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress123

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "9090:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress123
volumes:
   db_data: {}
Copy the code

Docker-compose build and run the application

Run in the directory docker-comemage. yml

docker-compose up -d
Copy the code

Enter http://0.0.0.0:9090 to go to the wordpress installation page

6. Bind domain name

Since other systems will be deployed on this machine later, wordpress is not exposed to port 80, and nginx will be used as the layer proxy before binding the domain name

1. Install nginx

yum install -y nginx
Copy the code

2. Configure nginx

# vim /etc/nginx/nginx.conf ... http { ... server { listen 80; server_name xxx.com; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REQUEST-URI $request_uri; proxy_set_header Cookie $http_cookie; proxy_pass http://localhost:9090; proxy_cookie_domain domino.server nginx.server; proxy_redirect off; }}}Copy the code

3. Start nginx and set the startup to run automatically

systemctl start nginx.service
systemctl enable nginx.service
Copy the code

4. WordPress Settings, enter the wordpress management page

Set both urls to domain names

If you do not set the URL, the system automatically redirects to http://ip:port every time you access the domain name

Type xxxx.com in your browser and a personal blog is born.