展开

docker 服务及案例

最后发布时间 : 2024-03-27 19:49:49 浏览量 :

容器内部使用docker

docker run --rm -it   -p 10086:10086 \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v  /usr/bin/docker:/usr/bin/docker \
    -v /etc/docker/daemon.json:/etc/docker/daemon.json \
    -v /var/lib/docker:/var/lib/docker \
    ubuntu:jammy bash 
sed -i 's/http:\/\/cn.archive.ubuntu.com/https:\/\/mirrors.aliyun.com/g' /etc/apt/sources.list
version: "3.0"
services:
  mysql:
    image: mysql:8.0.21
    hostname: shanjun_mysql
    container_name: shanjun_mysql
    restart: always
    command:
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --lower-case-table-names=1
      --collation-server=utf8mb4_unicode_ci
    environment:
      - MYSQL_ROOT_PASSWORD=123456
      # - MYSQL_DATABASE=nacos_devtest
      # - MYSQL_USER=nacos
      # - MYSQL_PASSWORD=nacos
      - LANG=C.UTF-8
    networks: 
      - springcloud
    ports:
      - '23306:3306'
      - '23061:33060'
    volumes:
      - "./data/mysql8.0.21:/var/lib/mysql"
    healthcheck:
      test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
      interval: 5s
      timeout: 60s
      retries: 10

  # 初始化naocs
  # nacos-mysql-schema.sql
  # CREATE DATABASE mbiolance_cloud_nacos_prob_177 CHARACTER SET utf8 COLLATE utf8_bin;

  nacos:
    image: nacos/nacos-server:v2.3.0
    container_name: nacos-standalone-mysql
    hostname: nacos
    restart: always
    environment:
      - PREFER_HOST_MODE=shanjun_mysql
      - MODE=standalone
      - SPRING_DATASOURCE_PLATFORM=mysql
      - MYSQL_SERVICE_HOST=shanjun_mysql
      - MYSQL_SERVICE_DB_NAME=mbiolance_cloud_nacos_dev
      - MYSQL_SERVICE_PORT=3306
      - MYSQL_SERVICE_USER=root
      - MYSQL_SERVICE_PASSWORD=123456
      - MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
      - NACOS_AUTH_IDENTITY_KEY=2222
      - NACOS_AUTH_IDENTITY_VALUE=2xxx
      - NACOS_AUTH_TOKEN=xxx
    volumes:
      - ./logs/nacos2.3.0/:/home/nacos/logs
    networks: 
      - springcloud
    ports:
      - "28848:8848"
      - "29848:9848"
    depends_on:
      mysql:
        condition: service_healthy

  redis:
    image: redis:7.0.0-alpine
    container_name: shanjun_redis
    hostname: shanjun_redis
    restart: always
    networks: 
      - springcloud
    volumes:
      - ./data/redis7.0.0/data:/data:rw
      - ./conf/redis7.0.0:/usr/local/etc/redis
    command:
      redis-server /usr/local/etc/redis/redis.conf
    ports:
      - "26379:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "-a","xxxx","ping"] # ./data/redis7.0.0/conf/redis.conf
      interval: 10s
      timeout: 3s
      retries: 3

  mongo:
    image: mongo:7.0.5
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: rootroot
    ports:
      - 27017:27017
    volumes:
      - ./data/mongo7.0.5/db:/data/db

  mongo-express:
    image: mongo-express
    restart: always
    ports:
      - 28081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: rootroot
      ME_CONFIG_MONGODB_URL: mongodb://root:rootroot@mongo:27017/

  zookeeper:
    image: bitnami/zookeeper:3.8
    hostname: shanjun_zookeeper
    restart: always
    # user: 1000:1000
    networks: 
      - springcloud
    environment:
      # ZOOKEEPER_CLIENT_PORT: 2181
      # ZOOKEEPER_TICK_TIME: 2000
      ALLOW_ANONYMOUS_LOGIN: yes 
    ports:
      - 22181:2181
    volumes:
      # - ./data/zookeeper3.8:/bitnami # 存在权限问题
      - zookeeper_data:/bitnami
  
  kafka:
    image: bitnami/kafka:3.6.1
    hostname: shanjun_kafka
    restart: always
    # user: 1000:1000
    networks: 
      - springcloud
    depends_on:
      - zookeeper
    ports:
      - 9092:9092
    environment:
      # KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: shanjun_zookeeper:2181
      ALLOW_PLAINTEXT_LISTENER: yes
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT
      KAFKA_LISTENERS: CLIENT://:9092,EXTERNAL://:9093
      KAFKA_ADVERTISED_LISTENERS: CLIENT://shanjun_kafka:9092,EXTERNAL://localhost:9093
      KAFKA_CFG_INTER_BROKER_LISTENER_NAME: CLIENT
      # KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
    volumes:
      # - ./data/kafka3.6.1:/bitnami # 存在权限问题
      - kafka_data:/bitnami



volumes:
  zookeeper_data:
    driver: local
  kafka_data:
    driver: local
    
networks:
  springcloud:
    external: true