在 docker 执行 git 很慢是什么原因?

2022-11-17 09:37:43 +08:00
 yhm2046

在公司服务器中下载 image 镜像到本地,git status, git add, git commit 这些命令都很慢, 都运行几个小时,我查了一下在我一个人用服务器时候也是很慢, 另外在 docker 而是直接在硬盘上的代码运行就是正常的, 这种情况是什么原因导致?

1838 次点击
所在节点    git
7 条回复
imdong
2022-11-17 09:45:47 +08:00
已知 docker 在 Mac 下,映射进去的目录,小文件性能很差。
amrnxcdt
2022-11-17 09:46:34 +08:00
docker 运行的容器是 overlayfs 文件系统,写入慢,用--mount 挂载 host 上的的路径进行读写就快一些。
参考:
https://docs.docker.com/storage/storagedriver/overlayfs-driver/
https://docs.docker.com/storage/bind-mounts/
seers
2022-11-17 09:48:35 +08:00
挂个 mem 盘进去看看,是不是磁盘导致的
yhm2046
2022-11-23 09:33:04 +08:00
@amrnxcdt 你好我用了 --mount 命令测试感觉还是没有快多少, 而且设置时间的命令也用不了

sudo docker run -d --privileged -it \
--mount type=bind,source=/datastore1/x9,target=/host \
--name sd_build_x9 sd_build_3 /bin/bash
amrnxcdt
2022-11-24 18:36:41 +08:00
@yhm2046 #4 你要提供更多信息大家才能帮你判断。比如你的 docker 版本和 host 系统是什么? docker 镜像是什么系统、镜像内和 host 上的 git 版本什么的。
yhm2046
2022-11-25 11:41:30 +08:00
@amrnxcdt 宿主机器:
Docker version 20.10.17, build 100c701
Description: Ubuntu 22.04.1 LTS

docker 镜像
sudo docker exec -it df01ded745cd /bin/bash
git version 2.7.4
Ubuntu 16.04.7 LTS

另外设置时间问题我已经解决了,参考 https://blog.csdn.net/ju_362204801/article/details/114383191
不过现在在 docker 里面编译出现报错, 我怀疑是挂载命令出错,因为我用-v 挂载是可以正常编译没有问题的
//原来的命令
sudo docker run --privileged -it -d -v /datastore1/x9r:/host --name sd_build sd_build_3 /bin/bash
//报错 log
make[2]: Entering directory '/host/x9/ptg4.1/buildsystem/atf/atf/arm-trusted-firmware'
/bin/sh: 1: /tool/gcc_linaro/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc: not found
Including services/spd/trusty/trusty.mk
Building x9
CC lib/libc/abort.c
CC lib/libc/assert.c
make[2]: /tool/gcc_linaro/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc: Command not found
CC lib/libc/exit.c
make[2]: /tool/gcc_linaro/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc: Command not found
Makefile:802: recipe for target '/host/x9/ptg4.1/buildsystem/atf/atf/arm-trusted-firmware/sml/x9/release/libc/abort.o' failed
make[2]: *** [/host/x9/ptg4.1/buildsystem/atf/atf/arm-trusted-firmware/sml/x9/release/libc/abort.o] Error 127
CC lib/libc/memchr.c
make[2]: *** Waiting for unfinished jobs....
Makefile:802: recipe for target '/host/x9/ptg4.1/buildsystem/atf/atf/arm-trusted-firmware/sml/x9/release/libc/assert.o' failed
make[2]: *** [/host/x9/ptg4.1/buildsystem/atf/atf/arm-trusted-firmware/sml/x9/release/libc/assert.o] Error 127
make[2]: /tool/gcc_linaro/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc: Command not found
Makefile:802: recipe for target '/host/x9/ptg4.1/buildsystem/atf/atf/arm-trusted-firmware/sml/x9/release/libc/exit.o' failed
make[2]: *** [/host/x9/ptg4.1/buildsystem/atf/atf/arm-trusted-firmware/sml/x9/release/libc/exit.o] Error 127
make[2]: /tool/gcc_linaro/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc: Command not found
Makefile:802: recipe for target '/host/x9/ptg4.1/buildsystem/atf/atf/arm-trusted-firmware/sml/x9/release/libc/memchr.o' failed
make[2]: *** [/host/x9/ptg4.1/buildsystem/atf/atf/arm-trusted-firmware/sml/x9/release/libc/memchr.o] Error 127
make[2]: Leaving directory '/host/x9/ptg4.1/buildsystem/atf/atf/arm-trusted-firmware'
sml_setup.mk:53: recipe for target 'atf_build' failed
make[1]: *** [atf_build] Error 2
make[1]: Leaving directory '/host/x9/ptg4.1/buildsystem/atf/atf/arm-trusted-firmware'
Makefile:1429: recipe for target 'build_ap2atf' failed
make: *** [build_ap2atf] Error 1
amrnxcdt
2022-11-25 20:26:13 +08:00
@yhm2046 #6 -v 和--mount 就是默认参数的区别,参考: https://docs.docker.com/storage/volumes/#choose-the--v-or---mount-flag

参考 make 的错误是 Entering directory ,应该是--mount 缺少参数了,如果-v 可以用直接用-v 就行。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/895836

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX