Docker:MacOs修改daemon.json

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
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
To configure a credential helper and avoid storing passwords unencrypted in the Docker configuration file, you can follow these steps: 1. Open the terminal on your system. 2. Run the following command to check if a credential helper is already configured: ``` docker-credential-* ``` If you see any output, it means a credential helper is already configured, and you can skip the next step. 3. Install the Docker-credential helper: - For Linux: ``` sudo apt-get install -y docker-credential-helpers ``` - For macOS using Homebrew: ``` brew install docker-credential-helper ``` - For Windows using Chocolatey: ``` choco install docker-credential-helper ``` 4. Once the installation is complete, configure the credential helper by creating a Docker configuration file (if it doesn't already exist): ``` touch ~/.docker/config.json ``` 5. Open the Docker configuration file using a text editor: ``` nano ~/.docker/config.json ``` 6. Add the following JSON snippet to the file, replacing `<credential-helper>` with the appropriate credential helper for your system (e.g., `secretservice` for Linux): ```json { "credsStore": "<credential-helper>" } ``` 7. Save the file and exit the text editor. 8. Restart the Docker daemon: - For Linux: ``` sudo systemctl restart docker ``` - For macOS using Homebrew: ``` brew services restart docker ``` - For Windows: ``` Restart-Service docker ``` After completing these steps, your Docker password should no longer be stored unencrypted in the `/root/.docker/config.json` file, and the warning should be resolved.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值