• 使用docker compose 构建多个镜像


    • 定义docker compose
      version: '3'
      
      services: 
        composedb:
          image: mysql/mysql-server
          container_name: composedb
          command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci
          restart: always
          ports:
           - "3306:3306"
          environment:
           MYSQL_ROOT_PASSWORD: pwd123456
           MYSQL_USER: test
           MYSQL_PASSWORD: pwd123456
          volumes:
           - /docker/network/beta/mysql-init:/docker-entrypoint-initdb.d  
        web:
          build: .
          container_name: aspnetcore
          ports:
           - "8004:80"
          #entrypoint: "sh ./wait-for-it.sh composedb:3306 -- sh  ./aspnetcore.sh"
          #command: ["./wait-for-it.sh", "composedb:3306", "--", "./aspnetcore.sh"]
          depends_on:
           - composedb
    • 修改初始化实力代码当数据库镜像初始化完毕后执行数据初始化
       public static async Task SeedAsync(IApplicationBuilder ApplicationBuilder, ILoggerFactory LoggerFactory, int? retry = 0)
              {
                  var retryForAvaibility = retry.Value;
                  using (var scope = ApplicationBuilder.ApplicationServices.CreateScope())//数据库未初始化失败会catch
                  {
                      try
                      {
                          var context = (UserContext)scope.ServiceProvider.GetService(typeof(UserContext));
                          var logger = (ILogger<UserContextSeed>)scope.ServiceProvider.GetService(typeof(ILogger<UserContextSeed>));
                          logger.LogDebug("Begin UserContextSeed SeedAsyc");
                          context.Database.Migrate();
                          if (!context.Users.Any())
                          {
                              context.Add(new Model.UserInfo { Name = "cyao", Company = "nocompany", Title = "软件工程师" });
                              context.SaveChanges();
                          }
                      }
                      catch (System.Exception ex)
                      {
                          retryForAvaibility++;
                          if (retryForAvaibility > 10)
                          {
                              var logger = LoggerFactory.CreateLogger(typeof(UserContextSeed));
                              logger.LogError(ex.Message);
                              await SeedAsync(ApplicationBuilder, LoggerFactory, retryForAvaibility);
                          }
                      }
                  }
              }
    • 其他的一些问题
      1.高版本的MySQL 加密方法使用caching_sha2_password
      2.低版本的Mysql创建的用户会有权限问题
      使用root用户进入到bash
      然后执行:
      GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' WITH GRANT OPTION;
    • liunx 跑到对应的docker-compose 文件路径后执行build 然后将docker-compose up起来
    • docker-compose build 构建dockers-compose镜像
    • docker-compose up
    • docker-compose down
  • 相关阅读:
    mysql怎么导入大文件的sql文件
    php函数研究
    php实现实现代码多主从,切换,轮询,健康检查
    php实现单个用户禁止重复登录,防止同一用户同时登陆
    php使用p3p实现cookies跨域设置 实现单点登录,全站登录
    实现页面浏览统计
    遍历目录删除指定MD5值的文件
    boot.img的修改
    “逃离大厦”游戏的破解
    Android漏洞——将Android恶意代码隐藏在图片中
  • 原文地址:https://www.cnblogs.com/chongyao/p/9204152.html
Copyright © 2020-2023  润新知