本文最后更新于:June 30, 2023 pm

本文作者:[wangwenhai] # 概要:记录近期工作中的一些常见操作.

1.Docker相关

1.1 Windows下

windows安装Docker首先要启用Hyper-V:

  1. 可以通过【程序和功能】=》【打开或关闭 Windows 功能】=》勾选【Hyper-V】来启用Hyper-V,

    image-20200516160810446

    image-20200516160854773

  1. 也可以通过管理员执行以下Powershell脚本:

    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

1.2 Linux下

  1. Ubuntu - server 安装Docker

    sudo apt-get install apt-transport-https  ca-certificates curl gnupg-agent software-properties-common -y
    sudo add-apt-repository  "deb [arch=amd64] https://download.docker.com/linux/ubuntu   $(lsb_release -cs)   stable"
    sudo apt-get update  -y
    sudo apt-get install docker-ce docker-ce-cli containerd.io -y
  2. Docker强制删除容器

    
    1. 删除所有容器
    # 先停止所有容器 
    $ docker stop $(docker ps -a -q) 
    # 删除 
    $ docker rm $(docker ps -a -q)
    2. 批量删除部分容器
    # 先停止所有容器 
    $ docker stop $(docker ps | grep rock | awk '{print $1}') 
    # 删除 
    $ docker rm $(docker ps -a| grep rock | awk '{print $1}')
  1. UbuntuServer安装MINIKUBE

    curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
    chmod +x minikube
    sudo mkdir -p /usr/local/bin/
    sudo install minikube /usr/local/bin/
    minikube start --registry-mirror=https://registry.docker-cn.com --memory=4096 --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
  2. DockerMysql8认证问题

    Navicat连接失败的时候:

    alter user root@localhost identified by 'password' password expire never;
    alter user root@localhost identified with mysql_native_password by 'password';
    flush privileges;

    2. 环境搭建

我们有时候需要快速搭建开发环境,比如数据库之类的,我这里总结了一个ComposeFile,直接即可搭建Mongo,Mysql,Redis开发环境。

version: '3.1'
# 定义网络
# 节点	IP
# Mysql	      192.168.1.100/24
# Mongodb	  192.168.1.101/24
# Redis	      192.168.1.102/24
networks:
  ezlinker_net:
    driver: bridge
    ipam:
      config:
        - subnet: 192.168.1.0/24
# 定义服务
services:
  # Mysql
  mysql:
    # 使用最新版Mysql
    image: mysql
    container_name: "ezlinker_mysql"
    # 环境变量
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: "root"
      MYSQL_USER: 'root'
      MYSQL_PASS: 'root'
    # 映射数据卷
    volumes:
      - ~/docker/ezlinker/mysql8/data:/var/lib/mysql
      - ~/docker/ezlinker/mysql8/log:/var/log/mysql
      - ~/docker/ezlinker/mysql8/mysql-files:/var/lib/mysql-files
    restart: always
    # 对外断口
    ports:
      - 3306:3306
      - 33060:33060
    # 启动后执行命令
    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
      --max_allowed_packet=128M;
    # 日志限制
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"
    # 网络
    networks:
      ezlinker_net:
        ipv4_address: 192.168.1.100
  # Mongodb
  mongo:
    image: mongo
    container_name: ezlinker_mongo
    volumes:
      - ~/docker/ezlinker/mongodb/db:/data/db
      - ~/docker/ezlinker/mongodb/configdb/:/data/configdb
    ports:
      - "27017:27017"
    restart: always
    command:
      --bind_ip 0.0.0.0
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: ezlinker_mongo
    networks:
      ezlinker_net:
        ipv4_address: 192.168.1.101
  # Redis
  redis:
    image: redis
    container_name: ezlinker_redis
    command: redis-server --requirepass ezlinker_redis --appendonly yes
    ports:
      - "56379:6379"
    volumes:
      - ~/docker/ezlinker/redis/data:/data
    restart: always
    networks:
      ezlinker_net:
        ipv4_address: 192.168.1.102

直接用docker compose来构建即可:

docker-compose up -d

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!

Erlang基于TCP协议的服务器开发 Previous
选择 Next