188.mysql_lei11

发表于 linux 分类,标签:
定义一条网络
docker network create --subnet=172.2.0.0/16 lei11
docker network rm lei11
docker-compose -f nginx_lei11 up -d
查看网络
docker network ls
查看网络下所有容器
docker network inspect lei11

创建库和表
CREATE DATABASE message_board;

USE message_board;CREATE TABLE messages (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    message TEXT NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);

mysql
#version: '3.8'

services:
  mysql:
    image: registry.cn-hangzhou.aliyuncs.com/leiuvn/mysql:5.7
    container_name: mysql_lei11
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: shimujiuxia  # 设置 MySQL root 用户密码
      MYSQL_DATABASE: lei11  # 设置默认数据库
      MYSQL_USER: lei11  # 设置用户
      MYSQL_PASSWORD: shimujiuxia  # 设置用户密码
    networks:
      lei11:
        ipv4_address: 172.2.0.2
    ports:
      - "3306:3306"  # 暴露端口
    volumes:
      - /data/mysql_lei11/:/var/lib/mysql/  # 映射数据目录到主机
        - /etc/localtime:/etc/localtime:ro
            - /etc/timezone:/etc/timezone:ro

volumes:
  mysql_data:
    driver: local
    driver_opts:
      type: none
      device: /data/mysql_lei11/  # 将此路径修改为主机上的实际路径
      o: bind

networks:
  lei11:
    external: true

#创建网络
#docker network create --subnet=172.2.0.0/16 lei11

#networks:
#  lei11:
#    ipam:
#      config:
#        - subnet: 172.2.0.0/16

lei11
services:
  nginx:
    container_name: lei11
    image: registry.cn-hangzhou.aliyuncs.com/leiuvn/tengine-php715:v3
    ports:
      - "8003:80"
    volumes:
      - /data/nginx_conf/lei11.com/:/opt/verynginx/openresty/nginx/conf/vhost/:ro
#      - /data/nginx_ssl/lei11.com/:/opt/verynginx/openresty/nginx/conf/ssl/:ro
      - /data/wwwroot/lei11.com:/data/wwwroot/lei11.com
      - /etc/localtime:/etc/localtime:ro
            - /etc/timezone:/etc/timezone:ro
    restart: always
    networks:
      lei11:
        ipv4_address: 172.2.0.3  # 指定固定IP地址

networks:
  lei11:
    external: true


获取容器ip
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql_container

获取网络ip
docker inspect mysql_container | jq -r '.[0].NetworkSettings.Networks.mynet.IPAddress'


0 篇评论

发表我的评论