dockerfile中CMD和RUN的区别
背景: 在使用 docker-compose 构建镜像时, 对 nextjs service 执行 RUN npm install 报错, 找不到 package.json 文件 原因: volume 中共享的文件夹, 是在容器启动时才开始共享, 在构建时没有共享, 导致 RUN 找不到 package.json, 而 CMD 才是容器运行时执行的命令 在 Dockerfile 中,CMD 和 RUN 是两个不同的指令,它们用于不同的目的和阶段: RUN - 用途:RUN 指令用于在构建 Docker 镜像时执行命令。 - 执行阶段:它在 Docker 镜像的构建过程中运行,生成一个新的镜像层。 - 结果:RUN 命令的结果被永久保存在镜像中,成为镜像的一部分。每次执行 RUN 时,都会创建一个新的镜像层。 - 常见用途: - 安装软件包和依赖项。 - 下载和解压文件。 - 编译源代码。 - 创建目录和文件。 - 配置环境和系统设置。 CMD - 用途:CMD 指令用于指定容器启动时要执行的命令。 - 执行阶段:它在容器启动时运行,而不是在镜像构建时。 - 结果:CMD 命令的结果不会保存在镜像中,因为它是容器运行时的指令。 - 常见用途: - 运行应用的主进程。 - 执行容器的默认命令。 - 可以被 docker run 命令中的命令覆盖。 配置示例 # .Go File Server
使用 go 内置 http 快速开启文件服务器 func main() { // 方式1 // http.ListenAndServe(":8080", http.FileServer(http.Dir("./public"))) // 方式2: 可自动生成对应文件列表页面 fs := http.FileServer(http.Dir("public")) // http.Handle("/public/", http.StripPrefix("/public/", fs)) // http.Handle("/", http.StripPrefix("/public/", fs)) http.Handle("/", fs) http.ListenAndServe(":8080", nil) }Sql Count With Condition
多表 left join 后, 使用 count 查询需要使用 distinct, 如果 count 里需要再次添加条件, 使用 distinct if(…) # 不做聚合查询 select company.id as company_id, company.name as company_name, vacancy.id as vacancy_id, vacancy.name as vacancy_name, shop.id as shop_id, shop.shop_name as shop_name, course.id as course_id, course.title as course_name from tb_company company left join tb_position vacancy on vacancy.company_id = company.id left join tb_shop shop on shop.company_id = company.id left join tb_shop_curriculum course on course.shop_id = shop.id where (vacancy.Buffer-String()-和-Buffer-String()
b1 := bytes.Buffer{} // 非指针 b2 := bytes.NewBuffer([]byte{}) // 指针 b3 := &bytes.Buffer{} // 指针, 等同于 b2 b1.WriteString("abc") b2.WriteString("abc") fmt.Println(b1) // {[97 98 99] 0 0} fmt.Println(b1.String()) // abc fmt.Println(b2) // abc 原因: *Buffer 有方法 String(), Buffer 没有 String() 方法. fmt.Println(b1), 就是 fmt 将 b1 按普通结构体进行输出: 分别输出各项 fmt.Println(b1.String()), 调用了 *Buffer 的 String() 方法 fmt.Println(b2), 自动调用 *Buffer 的 String() 方法 参考自 stackoverflowgin-middleware-注意事项
1. gin middleware 如果要中止后面中间件及所有程序的执行, 需要使用 c.Abort() + return 其中 Abort 会中止其后的中间件及页面处理程序, 而不会中止当前中间件函数内的余下程序, 使用 return 来中止当前中间件内后部的程序 func RejectMethodsExceptGet() gin.HandlerFunc { rejectMethods := map[string]struct{}{ "POST": {}, "DELETE": {}, "PUT": {}, "PATCH": {}, } return func(c *gin.Context) { if _, exist := rejectMethods[c.Request.Method]; exist { c.AbortWithStatusJSON(403, gin.H{ "err_msg": "invalid method", }) return } c.Next() } } 2. 中间件 Use 需要写在路由注册之前, 否则将不对之前注册的路由起作用 r := gin.New() r.Use(RejectMethodsExceptGet()) r.GET("/test", func(c *gin.Context) { example := c.MustGet("example").(string) // it would print: "12345" log.go-routine-使用外部变量问题
for i := 0; i < 10; i++ { go func() { fmt.Println(i) } } time.Sleep(time.Second) // 10,10,10,10,... 使用 go vet 检查 // 修改 for i := 0; i < 10; i++ { go func() { i2 := i fmt.Println(i2) } } // 或者(推荐) for i := 0; i < 10; i++ { go func(i int) { fmt.Println(i) }(i) } time.Sleep(time.Second) 参考 https://www.jianshu.com/p/e5f328819d4bgit-创建远程分支---从远程分支拉取本地不存在的分支
原文 新建远程分支 git push origin remote_branch_name:local_branch_name // remote_branch_name 是远程分支的名字 // local_branch_name 是本地分支的名字 git branch -a // 查看所有分支(远程+本地) 删除远程分支 git push origin :remote_branch_name // 或 git push origin --delete remote_branch_name 原文 git fetch git checkout -b local_branch_name origin/remote_branch_nameforeach-中使用-&地址符时,-最后要释放-value
$arr = [1,2,3]; foreach($arr as $key=> &$value){ if ($key){ $value = $value +1; } } unset($value); // 要注意翻译 $value, 否则后面如果还要用到 $value 时, 会指向 $arr 的最后一个元素dingo-api-返回-response--array()--setStatusCode()
phpstorm 对 $this->response->item(***)->setStatusCode(***) 中的 item() 和 setStatusCode() 都有提示, 找了下 Dingo\Api\Routing\Helpers trait类 中的 __call() 方法 public function __call($method, $parameters) { if (method_exists($this->response(), $method) || $method == 'array') { return call_user_func_array([$this->response(), $method], $parameters); } throw new ErrorException('Undefined method '.get_class($this).'::'.$method); } 意为调用 $this->response() 类( Factory类)的 $method (也就是 array() 方法), 并将 $parameters 作为参数 也就是 Factory 类的 array() 方法, 没想到 在 Factory 类中, array() 方法也是通过 __call() 魔术方法调用的… 另: call_user_func_array() 方法: 调用回调函数,并把一个数组参数作为回调函数的参数 如果调用的方法是一个类方法, 那么用 数组将 类名和方法名 组合起来 [$this->response(), $method] 表示回调方法$_ENV-&-getenv()
php 中 $_ENV & getenv() 获取的是环境变量, 如 windows 中 高级系统设置中的环境变量 或 linux 中 export 设置 getenv() 或 $_ENV 获取的是(系统)环境变量, 而不是 .env 文件. 在默认variables_order = "GPCS" 时, laravel 中使用 $_ENV 不能获取到(系统)环境变量, 但是可以获取到 .env 中的变量, 是因为 laravel 在初始化时使用 phpdotenv 将 .env 中的值添加到 $_ENV 中了. 另外 laravel 中 getenv() 本来就可以获取到(系统)环境变量, 也可以获取到 .env 文件中的设置的环境变量, 是因为 laravel(phpdotenv) 用 putenv() 设置了请求期间内有效的环境变量. ini_set() 配置可修改范围 参考php手册 laravel 初始化 dotenv 参考文章 Laravel ENV—— 环境变量的加载与源码解析
Recent Posts
Tags
- apache 4
- axios 1
- benchmark 1
- c 1
- canvas 1
- centos 3
- channel 1
- crontab 1
- css 2
- docker 4
- fail2ban 1
- frp 1
- gin 1
- github 1
- go 26
- goaccess 1
- goroutine 1
- http 1
- https 1
- jetbrains 1
- jquery 1
- js 2
- linux 20
- mermaid 1
- mysql 10
- nginx 3
- node 1
- php 43
- prisma 1
- react 8
- server 1
- ssh 2
- tarojs 1
- tcp/ip 1
- token 1
- ubuntu 1
- ufw 1
- unit-test 1
- vmware 1
- vscode 1
- vue 12
- yum 1
- 域名 3
- 安全 2
- 微信 3
- 算法 3