Docker:MacOs修改daemon.json
当我们自己创建dockerfile的时候,难免会下载各种各样的环境,但是docker默认的镜像速度又实在感人.
比如说一个很简单的需要java8依赖的dockerfile
FROM java:8
VOLUME /Users/zc/Desktop/md/dockerfilefile/volumeone
ADD crud-0.0.1-SNAPSHOT.jar demo.jar
EXPOSE 8082
ENTRYPOINT ["java","-jar","demo.jar"]
就会报错
ZHR:dockerfilefile zc$ docker build -f dockerfile -t crud1.0 .
[+] Building 80.4s (4/4) FINISHED
=> [internal] load build definition from dockerfile 0.0s
=> => transferring dockerfile: 195B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> ERROR [internal] load metadata for docker.io/library/java:8 80.3s
=> [auth] library/java:pull token for registry-1.docker.io 0.0s
------
> [internal] load metadata for docker.io/library/java:8:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to copy: httpReadSeeker: failed open: failed to do request: Get https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/d2/d23bdf5b1b1b1afce5f1d0fd33e7ed8afbc084b594b9ccf742a5b27080d8a4a8/data?verify=1626777656-AcJYIybMIWn97Norf7Q7tcm%2Fu34%3D: Service Unavailable
甚至*之后也报错!太过分啦
ZHR:dockerfilefile zc$ docker build -f dockerfile -t crud1.0 .
[+] Building 12.3s (4/4) FINISHED
=> [internal] load build definition from dockerfile 0.0s
=> => transferring dockerfile: 37B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> ERROR [internal] load metadata for docker.io/library/java:8 12.2s
=> [auth] library/java:pull token for registry-1.docker.io 0.0s
------
> [internal] load metadata for docker.io/library/java:8:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to do request: Head https://registry-1.docker.io/v2/library/java/manifests/8: net/http: TLS handshake timeout
从网上找也没有找到答案,各种答非所问,或者就不是针对macos,而是针对windows或者linux的,但是,这些搜索结果给我们了镜像的地址,下面是我复制出来的一段:
(1)本身网速太慢,无法下载;
(2)在Docker容器中配置的镜像有误,或镜像太水,比如下面两款镜像,分别是阿里云和中科院的
中科院的镜像
{
"registry-mirrors":["https://docker.mirrors.ustc.edu.cn"]
}
阿里云的镜像
{
"registry-mirrors":["https://6kx4zyno.mirror.aliyuncs.com"]
}
经过本人多次测试,发现还是阿里云的好用,所以强烈推荐这款
然后,就是需要修改我们的daemon.json了,找了Docker安装的路径,翻遍了也是没找到这个daemon.json到底在哪里,放弃了,准备关了docker.app算了,这个时候,突然灵光一闪,既然是应用,那他的设置里应该是有的,配置文件嘛,对不对
对,就是这个小齿轮!进去之后,终于在这里面找到了daemon关键字,那就尝试着修改一下吧
添加registry-mirrors后的文案放在这里:
{
"builder": {
"gc": {
"enabled": true,
"defaultKeepStorage": "20GB"
}
},
"registry-mirrors": [
"https://6kx4zyno.mirror.aliyuncs.com"
],
"features": {
"buildkit": true
},
"experimental": false
}
修改完成后点击Apply&Reatart,稍等一会完成后,再次执行,成功
ZHR:dockerfilefile zc$ docker build -f dockerfile -t crud1.0 .
[+] Building 54.9s (7/7) FINISHED
=> [internal] load build definition from dockerfile 0.0s
=> => transferring dockerfile: 37B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/java:8 53.6s
=> [internal] load build context 0.8s
=> => transferring context: 50.20MB 0.7s
=> [1/2] FROM docker.io/library/java:8@sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d 0.2s
=> => resolve docker.io/library/java:8@sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d 0.0s
=> => sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d 2.00kB / 2.00kB 0.0s
=> => sha256:d23bdf5b1b1b1afce5f1d0fd33e7ed8afbc084b594b9ccf742a5b27080d8a4a8 4.73kB / 4.73kB 0.0s
=> [2/2] ADD crud-0.0.1-SNAPSHOT.jar demo.jar 0.2s
=> exporting to image 0.2s
=> => exporting layers 0.2s
=> => writing image sha256:47cfd312159405bf42e3854b25ceabe4cd7e099f91893aab5ff791412bd5231d 0.0s
=> => naming to docker.io/library/crud1.0 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them