A, the point

  • Goal: Access blogs by domain name
  • Prerequisites: ECS(required), certificate (not required), domain name (required), docker/docker-compose/git installation

Docker installation

For details, see Installing Docker in CentOS7

Docker-compose installation

Docker-compose is a tool for defining and running multiple docker container applications. You can use YAML files to configure the application service, and then a command to deploy all the configured services.

Download the Docker – compose:

[root@localhost ~]https://get.daocloud.io/docker/compose/releases/download/1.24.0/docker-compose- # curl - L ` ` uname - s - ` uname -m ` > /usr/local/bin/docker-compose

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100   423  100   423    0     0    199      0  0:00:02  0:00:02 --:--:--   199

100 15.4M  100 15.4M    0     0  5381k      0  0:00:02  0:00:02 --:--:-- 22.6M

Copy the code

Change the permission of a file to executable:

[root@localhost ~]# chmod +x /usr/local/bin/docker-compose

Copy the code

Check whether the installation is successful:

[root@localhost ~]docker-compose -v

docker-compose version 124.. 0.build 0aa59064

Copy the code

Git Clone blog deployment files

Github address: Solo-for-Docker

Directory structure:

[root@localhost https]tree

.

├ ─ ─docker-compose.yml

├ ─ ─mysql

│ ├ ─ ─data

│ └ ─ ─init

│ └ ─ ─init.sql

└ ─ ─nginx

├ ─ ─conf

│ ├ ─ ─nginx.conf

│ └ ─ ─www.taotao-java.com.log

└ ─ ─www

└ ─ ─index.html



directoriesMay,files

[root@localhost https]

Copy the code

5. Nginx configuration

[root@localhost conf]# cat nginx.conf

gzip on;

gzip_min_length  1k;

gzip_buffers     4 16k;

gzip_http_version 1.1;

gzip_comp_level 2;

gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;

gzip_vary on;

gzip_proxied   expired no-cache no-store private auth;

gzip_disable   "MSIE [1-6]\.";



server_tokens off;

access_log off;



server {

  server_name www.taotao-java.com taotao-java.com;

  listen 80;

  location / {

    proxy_set_header X-Real-IP $remote_addr;

    proxy_set_header Host $http_host;

    proxy_pass http://solo:8080;

  }

  access_log  /etc/nginx/conf.d/www.taotao-java.com.log;



Copy the code

SQL > initialize init. SQL

[root@localhost init]# cat init.sql

CREATE DATABASE  `solo` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

grant all PRIVILEGES on*. *to root@The '%' identified by 'adminadmin';

flush privileges;

[root@localhost init]#

Copy the code

Docker-composing. Yml file

version: "2"



services:

  mysql:

    container_name: mysql

    image: mysql:5.7

    restart: always

    volumes:

      - ./mysql/data: /var/lib/mysql  // Mysql data file storage address

      - ./mysql/init:/docker-entrypoint-initdb.d // Initialize the SQL script

      - /etc/localtime:/etc/localtime:ro

    ports:

      - "6603:3306"   //6603 host port, 3306 container port

    environment:

      MYSQL_ROOT_PASSWORD: "adminadmin" // Root password of mysql

      TZ: "Asia/Shanghai"

    command: --max_allowed_packet=32505856

  solo:

    container_name: solo

    image: b3log/solo:latest  // Use the latest solo mirror

    restart: always

    ports:

      - "8080:8080"

    environment:

      RUNTIME_DB: "MYSQL"

      JDBC_USERNAME: "root"

      JDBC_PASSWORD: "adminadmin"

      JDBC_DRIVER: "com.mysql.jdbc.Driver"

      JDBC_URL: "jdbc:mysql://mysql:3306/solo? useUnicode=yes&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC"

    command: --listen_port=8080 --server_port=80 --server_scheme=http --server_host=taotao-java.com

  nginx:

     container_name: nginx

     image: nginx:latest

     restart: always

     ports:

       - "80:80"

     volumes:

       - "./nginx/conf:/etc/nginx/conf.d" // Map the nginx directory to the docker container

       - "./nginx/www/:/var/www/" // Map WWW directory to docker container, deploy static site

Copy the code

Note: SQL files in this./mysql/init folder will only be loaded if the DB data directory is empty (the first run of the database service). The /mysql/data folder should be empty. Docker-compose will be covered in more detail in the docker series, which will focus on the public number taotao-java

Eight, deployment,

  • Clone the project to your own server
  • Replace docker-composing. Yml, the domain name configured by nginx
  • Command to start the
[root@localhost https]ll

total 4

-rw-r--r--1.root root 1079 DecJune 2228: docker-compose.yml

drwxr-xr-x4.root root   30 Dec  5 03: 45 mysql

drwxr-xr-x4.root root   29 Dec  5 0326: nginx

[root@localhost https]docker-compose -f docker-compose.yml up -d

Starting nginx.done

Starting mysql.done

Starting solo.done

[root@localhost https]

Copy the code

Verify and visit blogs

  • In this case, you need to configure the local hosts

  • Domain name access blog