Directory

1 Intro

This section mainly introduces the use of docker to complete the deployment of the framework. There are two types of docker available:

First, make sure you have installed the docker environment on your machine. If not, please refer to docker install

2 Deploy Tars framework by Docker

If you want the source code to compile docker by yourself, see Install

Note: the difference is whether you want to deploy the business service in the image (not recommended, not convenient for upgrading the tars framework))

2.1 create a docker network

First, create a docker network to make sure this guide work properly on each OS platform. Tars will work exactly like it works on a VM or a cloud hosting machine.

# Create a bridge virtual network and set the name, subnet and gateway.
docker network create -d bridge --subnet=172.25.0.0/16 --gateway=172.25.0.1 tars

2.2 Start MySQL

docker run -d \
    --net=tars \
    -e MYSQL_ROOT_PASSWORD="123456" \
    --ip="172.25.0.2" \
    -v {PATH_ON_YOUR_COMPUTER}:/var/lib/mysql \
    -v /etc/localtime:/etc/localtime \
    --name=tars-mysql \
    mysql:5.6

{PATH_ON_YOUR_COMPUTER}: it is a folder that you should create by yourself where tars database will be deployed.

2.3 run tarscloud/framework docker

  1. Pull docker image
docker pull tarscloud/framework:v2.4.0

We highly recommended you to use a specific framework version tag to deploy your environment. Thus, you won’t be affected by a remote image update.

  1. Run docker image
# Mount timezone file /etc/localtime to container. Remove it if you don't have.
# expose port 3000 for web entry
# expose port 3001 for web authorization
docker run -d \
    --name=tars-framework \
    --net=tars \
    -e MYSQL_HOST="172.25.0.2" \
    -e MYSQL_ROOT_PASSWORD="123456" \
    -e MYSQL_USER=root \
    -e MYSQL_PORT=3306 \
    -e REBUILD=false \
    -e INET=eth0 \
    -e SLAVE=false \
    --ip="172.25.0.3" \
    -v {PATH_ON_YOUR_COMPUTER}:/data/tars \
    -v /etc/localtime:/etc/localtime \
    -p 3000:3000 \
    -p 3001:3001 \
    tarscloud/framework:v2.4.14

{PATH_ON_YOUR_COMPUTER}: it is a folder that you should create by yourself where tars framework will be deployed.

You can access http://localhost:3000 to access the Tars web management platform.

  1. Directory During creation, the directory / data / tars of docker will be mapped to the host directory / data / tars. After starting docker, please check the host directory / data / tars. Normally, the following directories will be created:

If these directories are not created, you can create them manually and restart docker

  1. Parameter interpretation

MYSQL_IP: IP of MySQL DB instance

MYSQL_ROOT_PASSWORD: Root password for MySQL

INET: The name of the network interface (as you can see in ifconfig, such as eth0) indicates the native IP bound by the framework. Note that it cannot be 127.0.0.1

REBUILD: Whether to rebuild the database is usually false. If there is an error in the intermediate installation and you want to reset the database, you can set it to true

SLAVE: Is this a slave node

MYSQL_USER: MySQL user. Will use root as default.

MYSQL_PORT: MySQL port

  1. Run platform replica

If you want to deploy multiple nodes, just execute docker run… On different machines. Pay attention to the parameter settings!

docker run -d \
    --name=tars-framework-slave \
    --net=tars \
    -e MYSQL_HOST="172.25.0.2" \
    -e MYSQL_ROOT_PASSWORD="123456" \
    -e MYSQL_USER=root \
    -e MYSQL_PORT=3306 \
    -e REBUILD=false \
    -e INET=eth0 \
    -e SLAVE=true \
    --ip="172.25.0.4" \
    -v /data/framework-slave:/data/tars \
    -v /etc/localtime:/etc/localtime \
    tarscloud/framework:v2.4.14

Attention: SLAVE environment is true

3 Docker Deploy Tars Node by Docker

  1. Pull image
docker pull tarscloud/tars-node:latest
  1. Run Node image
docker run -d \
    --name=tars-node \
    --net=tars \
    -e INET=eth0 \
    -e WEB_HOST="http://172.25.0.3:3000" \
    --ip="172.25.0.5" \
    -v /data/node:/data/tars \
    -v /etc/localtime:/etc/localtime \
    -p 9000-9010:9000-9010 \
    tarscloud/tars-node:latest

Note that if you use –net=host on the same machine and start the framework and tars-node images at the same time, it is not possible because the framework also contains a tarsnode, which will cause port conflicts and fail to start

4 Trouble Shot

If the docker still cannot open the management platform after running, you can check as follows:

docker --name=tars-framework \
    --net=tars \
    -e MYSQL_HOST="172.25.0.2" \
    -e MYSQL_ROOT_PASSWORD="123456" \
    -e MYSQL_USER=root \
    -e MYSQL_PORT=3306 \
    -e REBUILD=false \
    -e INET=eth0 \
    -e SLAVE=false \
    --ip="172.25.0.3" \
    -v /data/framework:/data/tars \
    -v /etc/localtime:/etc/localtime \
    -p 3000:3000 \
    tarscloud/framework:v2.4.14

If the web platform is open, but the error is displayed, you need to check the web problems. You can enter docker, please refer to check the web problems incheck the web problem

5 docker-compose

version: "3"

services:
  mysql:
    image: mysql:5.6
    container_name: tars-mysql
    ports:
      - "3307:3306"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: "123456"
    volumes:
      - ./mysql/data:/var/lib/mysql:rw
      - ./source/Shanghai:/etc/localtime
    networks:
      internal:
        ipv4_address: 172.25.1.2
  framework:
    image: tarscloud/framework:v2.4.14
    container_name: tars-framework
    ports:
      - "3000:3000"
    restart: always
    networks:
      internal:
        ipv4_address: 172.25.1.3
    environment:
      MYSQL_HOST: "172.25.1.2"
      MYSQL_ROOT_PASSWORD: "123456"
      MYSQL_USER: "root"
      MYSQL_PORT: 3306
      REBUILD: "false"
      INET: eth0
      SLAVE: "false"
    volumes:
      - ./framework/data:/data/tars:rw
      - ./source/Shanghai:/etc/localtime
    depends_on:
      - mysql
  node:
    image: tarscloud/tars-node:latest
    container_name: tars-node
    restart: always
    networks:
      internal:
        ipv4_address: 172.25.1.5
    volumes:
      - ./node/data:/data/tars:rw
      - ./source/Shanghai:/etc/localtime
    environment:
      INET: eth0
      WEB_HOST: http://172.25.1.3:3000
    ports:
      - "9000-9010:9000-9010"
    depends_on:
      - framework
networks:
  internal:
    driver: bridge
    ipam:
      config:
        - subnet: 172.25.1.0/16

7 docker mirror version

Notice:

The above execution mode is from the tarscloud/framework:v2.4.0