解决Docker build时 Sending build context to Docker daemon 过大的问题

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介:

当使用Dockerfile Build镜像时,有时会发现发送到Daemon的内容过大

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Sending build context to Docker daemon 4.358 GB
Step 0 : FROM xxx.xxx.com /centos :7
  ---> 218081f3bcdc
Step 1 : RUN  mkdir  -p  /data/mysql/base
  ---> Using cache
  ---> ac4aa04a93a1
Step 2 : RUN adduser mysql
  ---> Using cache
  ---> f30c90e0e589
Step 3 : ADD base  /data/mysql/base
  ---> 3666ada5715c
Removing intermediate container d65c5abdfe5c
Step 4 : ENTRYPOINT  /data/mysql/base/entrypoint .sh
  ---> Running  in  3be4e22baff7
  ---> a73907b2fbd5
Removing intermediate container 3be4e22baff7
Successfully built a73907b2fbd5
1
2
REPOSITORY    TAG   IMAGE ID            CREATED         VIRTUAL SIZE
marriadb     latest  a73907b2fbd5        25 seconds ago      530.9 MB



但是我们的Dokerfile 非常简单,那么这些多出来的内容是从哪里来的呢。

发现Docker Client会默认发送Dockerfile同级目录下的所有文件到Dockerdaemon中

 

解决办法有两种:

 

1.创建.dockerignore文件,把不需要的文件写到里面,该文件包含的目录不会被发送到Docker daemon中

 

2.就找个空目录只有dockerfile。

本文转自银狐博客51CTO博客,原文链接http://blog.51cto.com/foxhound/1825402如需转载请自行联系原作者

战狐
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
打赏
0
0
0
0
90
分享
相关文章
docker运行报错docker: Error response from daemon: AppArmor enabled on system but the docker-default prof
docker运行报错docker: Error response from daemon: AppArmor enabled on system but the docker-default prof
621 0
(已解决)Linux环境—bash: wget: command not found; Docker pull报错Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled
(已成功解决)Linux环境报错—bash: wget: command not found;常见Linux发行版本,Linux中yum、rpm、apt-get、wget的区别;Docker pull报错Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled
1337 68
(已解决)Linux环境—bash: wget: command not found; Docker pull报错Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled
error during connect: this error may indicate that the docker daemon is not running
error during connect: this error may indicate that the docker daemon is not running
508 0
docker pull mysql:8.0.26提示Error response from daemon: Get “https://registry-1.docker.io/v2/“: EOF错误
docker pull mysql:8.0.26提示Error response from daemon: Get “https://registry-1.docker.io/v2/“: EOF错误
docker中编译android aosp源码,出现Build sandboxing disabled due to nsjail error
在使用Docker编译Android AOSP源码时,如果遇到"Build sandboxing disabled due to nsjail error"的错误,可以通过在docker run命令中添加`--privileged`参数来解决权限不足的问题。
1515 1
7-13|docker build -t image-name:tag path/to/Dockerfile 这个命令具体什么意思
7-13|docker build -t image-name:tag path/to/Dockerfile 这个命令具体什么意思
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker
181 0
Docker在win10上报错,error during connect: In the default daemon configuration on Windows
Docker在win10上报错,error during connect: In the default daemon configuration on Windows
441 0
waiting for docker daemon: failed to start docker engine: dockerd failed to start: exit status 1
waiting for docker daemon: failed to start docker engine: dockerd failed to start: exit status 1
126 0