Docker deploys nginx and mysql and back-end services

First make sure that the server has docker installed

One, mysql

1. Install docker-compose

Compose supports Linux, macOS, and Windows 10 platforms. It is also very simple to install on Linux, from the official GitHub Release downloaded directly at the compiled binary files.

curl -L https://github.com/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

verification

docker-compose version

# 输出如下
docker-compose version 1.24.0, build 0aa59064
docker-py version: 3.7.2
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.1.0j  20 Nov 2018

2. Install mysql

docker pull mysql:5.7

mysql的docker-compose

version: '3.0'
services:
  db:
    # 目前 latest 版本为 MySQL8.x
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: w13579
    command:
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
      --sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    ports:
      - 3306:3306
  

Then execute: docker-compose up -d

Two, nginx

nginx的docker-compose

version: '2.0'

services:
  nginx:
    restart: always
    image: nginx:latest
    ports:
      - 8080:80
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./log:/var/log/nginx
      - ./html:/usr/share/nginx/html

Mounting of data volumes

mkdir nginx

In the nginx folder: nginx.conf, log, front-end html

Among them: nginx.conf

# 启动进程,通常设置成和 CPU 的数量相等
worker_processes  1;
events {
    # epoll 是多路复用 IO(I/O Multiplexing) 中的一种方式
    # 但是仅用于 linux2.6 以上内核,可以大大提高 nginx 的性能
    use epoll;
    # 单个后台 worker process 进程的最大并发链接数
    worker_connections  1024;
}
http {
    # 设定 mime 类型,类型由 mime.type 文件定义
    include       mime.types;
    default_type  application/octet-stream;
    # sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,对于普通应用,
    # 必须设为 on,如果用来进行下载等应用磁盘 IO 重负载应用,可设置为 off,以平衡磁盘与网络 I/O 处理速度,降低系统的 uptime.
    sendfile        on;
    # 连接超时时间
    keepalive_timeout  65;
    # 设定请求缓冲
    client_header_buffer_size 2k;
    # 配置虚拟主机 192.168.80.142
    server {
    # 监听的 IP 和端口,配置 192.168.80.142:80
        listen       80;
    # 虚拟主机名称这里配置 IP 地址
        server_name  192.168.239.128;
    # 所有的请求都以 / 开始,所有的请求都可以匹配此 location
        location / {
            # 使用 root 指令指定虚拟主机目录即网页存放目录
            # 比如访问 http://ip/index.html 将找到 /usr/local/docker/nginx/html/html80/index.html
            root   /usr/share/nginx/html/build;
            # 指定欢迎页面,按从左到右顺序查找
            index  index.html index.htm;
        }
    }
}

Three, back-end services

docker-compose.yml

version: '3'
services:
  catalogue-server:
    image: 10.1.119.12/gx/catalogue-server:test
    network_mode: "host"
    restart: always
    container_name: catalogue
    environment:
        MYSQL_IP_PORT: "localhost:3306"
        MYSQL_DB_NAME: "homework"
        MYSQL_USERNAME: "root"
        MYSQL_PASSWORD: "w13579"

 

Guess you like

Origin blog.csdn.net/shujuelin/article/details/108845438