$ docker inspect {container_id} | grep Mounts -A 20
"朱小贱" 发布的文章
v4.6.1
版本可用
Registered Name: https://zhile.io
License Key: 48891cf209c6d32bf4
docker启动不起来,查看日志错误内容如下:
$ docker logs -f go-advertise
"no such file or directory"
$ docker logs -f go-advertise standard_init_linux.go:211: exec user process caused "no such file or directory"
因为我是在Windows环境下,启动脚本是
run.sh
。打开git bash
,设置fileformat
为unix
。$ vim run/sh :set ff=unix
创建不了文件夹
$ docker logs -f go-advertise mkdir: can't create directory '/data/logs/': No such file or directory /run.sh: line 3: can't create /data/nginx/log/go-advertise.error.log: nonexistent directory
入口文件是
run.sh
,代码如下:#!/bin/sh mkdir -p /data/logs/golang/ ./go-advertise start -env=dev >> /data/nginx/log/go-advertise.error.log 2>&1
我在
Dockerfile
创建日志目录RUN mkdir -p /data/nginx/log && \n mkdir -p /data/logs/golang/ && \n touch /data/nginx/log/go-advertise.error.log
参考链接:docker启动报错:standard_init_linux.go:211: exec user process caused "no such file or directory"
拉取私有仓库报错
本地开发环境的golang
版本是1.15,原本我以为是自己没有仓库的权限(公司的项目)。但是加了还是不行,也设置了GOPRIVATE
。但还是不行,看了网上很多的帖子说要设置git
。但是说得也不清楚,有点知其然而不知其所以然。
go get gitlab.xxx.com/advertise/go-modules: module gitlab.xxx.com/advertise/go-modules: reading https://goproxy.io/gitlab.xxx.com/advertise/go-modules/@v/1.1.1: 404 Not Found
终于看到这篇文章,总算是清楚了。特此记录下来!以下内容来自转载的文章。
直接使用 go get
直接使用 go get ...
添加私有仓库依赖时,会出现以下错误:
get "gitlab.com/xxx": found meta tag get.metaImport{Prefix:"gitlab.com/xxx", VCS:"git", RepoRoot:"https://gitlab.com/xxx.git"} at //gitlab.com/xxx?go-get=1
go get gitlab.com/xxx: git ls-remote -q https://gitlab.com/xxx.git in /Users/sulin/go/pkg/mod/cache/vcs/91fae55e78195f3139c4f56af15f9b47ba7aa6ca0fa761efbd5b6e2b16d5159d: exit status 128:
fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled
Confirm the import path was entered correctly.
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
从错误信息可以明显地看出来,我们使用私有仓库时通常会配置ssh-pubkey
进行鉴权,但是go get
使用https
而非ssh
的方式来下载依赖,从而导致鉴权失败。
GOPROXY错误
如果配置了GOPROXY
代理,错误信息则是如下样式:
go get gitlab.com/xxx: module gitlab.com/xxx: reading https://goproxy.io/gitlab.com/xxx/@v/list: 404 Not Found
P.S:这个就是我遇到的问题o(╥﹏╥)o
1.13 版本解决方案
在1.13版本之后,前面介绍的解决方案又会导致go get
出现另一种错误:
get "gitlab.com/xxx/zz": found meta tag get.metaImport{Prefix:"gitlab.com/xxx/zz", VCS:"git", RepoRoot:"https://gitlab.com/xxx/zz.git"} at //gitlab.com/xxx/zz?go-get=1
verifying gitlab.com/xxx/zz@v0.0.1: gitlab.com/xxx/zz@v0.0.1: reading https://sum.golang.org/lookup/gitlab.com/xxx/zz@v0.0.1: 410 Gone
这个错误是因为新版本go mod
会对依赖包进行checksum校验,但是私有仓库对sum.golang.or
g是不可见的,它当然没有办法成功执行checksum。
也就是说强制git
采用ssh
的解决办法在1.13版本之后GG了。
当然Golang
在堵上窗户之前,也开了大门,它提供了一个更方便的解决方案:GOPRIVATE
环境变量。解决以上的错误,可以这样配置:
export GOPRIVATE=gitlab.xxx.com/advertise/go-modules
# 1.15版本以后可以用以下命令设置 go 环境变量
go env -w GOPRIVATE=gitlab.xxx.com/advertise/go-modules
它可以声明指定域名为私有仓库,go get
在处理该域名下的所有依赖时,会直接跳过GOPROXY
和CHECKSUM
等逻辑,从而规避掉前文遇到的所有问题。
另外域名gitlab.com/xxx
非常灵活,它默认是前缀匹配的,所有的gitlab.com/xxx
前缀的依赖模块都会被视为private-modules
,它对于企业、私有Group等有着一劳永逸的益处。
提示:如果你通过ssh公钥访问私有仓库,记得配置git拉取私有仓库时使用ssh而非https。
可以通过命令git config ...
的方式来配置。也可以像我这样,直接修改~/.gitconfig
添加如下配置:
[url "git@gitlab.meiyou.com:"]
insteadof = https://gitlab.meiyou.com/
[url "git@github.com:"]
insteadof = https://github.com/
[url "git@gitlab.com:"]
insteadof = https://gitlab.com/
即可强制go get针对github.com与gitlab.com使用ssh而非https。
{
"registry-mirrors": [
"https://docker.mirrors.ustc.edu.cn", ## 中科大
"https://sfqan33a.mirror.aliyuncs.com" ## 阿里云
]
}