专业编程基础技术教程

网站首页 > 基础教程 正文

docker build使用Git Repo构建image错误解决办法

ccvgpt 2024-07-19 12:54:04 基础教程 13 ℃

操作系统版本: CentOS 7.4

Docker版本: Docker CE 19.03.8

docker build使用Git Repo构建image错误解决办法


docker build使用Git Repo构建image时报如下错误:

$ docker build -t nginx:v1 https://github.com/MarlonMa/docker_test.git
unable to prepare context: unable to 'git clone' to temporary context directory: error initializing submodules: usage: git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
   or: git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
   or: git submodule [--quiet] init [--] [<path>...]
   or: git submodule [--quiet] deinit [-f|--force] [--] <path>...
   or: git submodule [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
   or: git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
   or: git submodule [--quiet] foreach [--recursive] <command>
   or: git submodule [--quiet] sync [--recursive] [--] [<path>...]
: exit status 1

报错原因为Docker 19.03.8会在“git clone”之后运行“git submodule update --init --recursive --depth=1”,Git 1.8.3.1不支持--depth参数(CentOS 7.4自带的Git版本为1.8.3.1),需要升级Git,操作如下:

1.安装IUS源,该源提供git2u包
yum install https://centos7.iuscommunity.org/ius-release.rpm
2.移除git,安装git2u
yum swap git git2u
3.查看git升级后版本
git version

升级Git后构建image成功:

$ docker build -t nginx:v1 https://github.com/MarlonMa/docker_test.git
Sending build context to Docker daemon  57.86kB
Step 1/2 : FROM nginx
latest: Pulling from library/nginx
54fec2fa59d0: Pull complete
4ede6f09aefe: Pull complete
f9dc69acb465: Pull complete
Digest: sha256:86ae264c3f4acb99b2dee4d0098c40cb8c46dcf9e1148f05d3a51c4df6758c12
Status: Downloaded newer image for nginx:latest
 ---> 602e111c06b6
Step 2/2 : RUN echo '<h1>Hello World!</h1>' > /usr/share/nginx/html/index.html
 ---> Running in ef7015ba5dae
Removing intermediate container ef7015ba5dae
 ---> 28f5298fef02
Successfully built 28f5298fef02
Successfully tagged nginx:v1
$ docker image ls nginx:v1
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               v1                  28f5298fef02        23 seconds ago      127MB

Tags:

最近发表
标签列表