docker out of disk space

2019-08-30 04:30发布

问题:

I'm hainvg trouble with docker and volume size. I'm running docker-machine with three containers. The one giving me trouble is the MySQL container which has a data-only container for persistance. When I try to import a mysql file, mysql complains that the table is full, which really means that the disk is out of space. Looking at the system, I see the problem, but don't know how to correct it:

 _                 _   ____     _            _
 | |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
 | '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
 | |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
 |_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
 Boot2Docker version 1.8.1, build master : 7f12e95 - Thu Aug 13 03:24:56 UTC
 2015
 Docker version 1.8.1, build d12ea79
 docker@default:~$ sudo -i
 Boot2Docker version 1.8.1, build master : 7f12e95 - Thu Aug 13 03:24:56 UTC
 2015
 Docker version 1.8.1, build d12ea79
 root@default:~# df -h
 Filesystem                Size      Used Available Use% Mounted on
 tmpfs                   896.6M    112.4M    784.2M  13% /
 tmpfs                   498.1M    136.0K    498.0M   0% /dev/shm
 /dev/sda1                 2.8G      2.7G         0 100% /mnt/sda1
 cgroup                  498.1M         0    498.1M   0% /sys/fs/cgroup
 none                    462.2G     32.8G    429.5G   7% /Users
 /dev/sda1                 2.8G      2.7G         0 100%
 /mnt/sda1/var/lib/docker/aufs
 none                      2.8G      2.7G         0 100%
 /mnt/sda1/var/lib/docker/aufs/mnt/0a90321d2e941e31385a4c4096e
 none                      2.8G      2.7G         0 100%
 /mnt/sda1/var/lib/docker/aufs/mnt/bca6fc0c017233ed634e7e19284
 none                      2.8G      2.7G         0 100%
 /mnt/sda1/var/lib/docker/aufs/mnt/7e432f020ee8fc9c6a211c810e5

I created the docker-machine like this, which I thought would give me the space I need, but it has not.

docker-machine create --virtualbox-disk-size 4000 -d virtualbox default

I'm creating the mysql image like this

#!/bin/bash

echo "- checking that the image exists"
IMAGE=$(docker images | grep cp_mysql)
if [ -z "$IMAGE" ]; then
  echo '- image does not exist, building'
  docker build -t cp_mysql -f Dockerfile-app .
fi


echo "- checking if the mysql data volume exists"
DATA_VOL=$(docker ps -a | grep cp_mysql_data)

# if empty
if [ -z "$DATA_VOL" ]; then
  echo '- data volume is empty - building'
  DATA_VOL=$(docker build -t data -f Dockerfile-data_vol . | tail -n 1 | awk '{print $3}')
  docker run --name cp_mysql_data $DATA_VOL
  echo "- build data volume: $DATA_VOL"
else
  DATA_VOL=$(echo $DATA_VOL | awk '{print $1}')
  echo "- data volume is not empty - using existing volume: $DATA_VOL"
fi

echo '- check if existing cp_mysql_app exists'

APP=$(docker ps -a | grep cp_mysql_app)

if [ -z "$APP" ]; then
  echo '- the app does not exist, let us create it'
  docker run \
    --restart=always \
    --name cp_mysql_app \
    --restart=always \
    --volumes-from=cp_mysql_data \
    -e MYSQL_USER=cp \
    -e MYSQL_PASSWORD=cp \
    -e MYSQL_DATABASE=cp \
    -e MYSQL_ROOT_PASSWORD=root \
    -d \
    -p 3306:3306 cp_mysql
else
  echo '- the does exist, let us just run it'
  docker start cp_mysql_app
fi

Here's my docker info for that machine

docker@default:~$ docker info
Containers: 0
Images: 0
Storage Driver: aufs
 Root Dir: /mnt/sda1/var/lib/docker/aufs
 Backing Filesystem: tmpfs
 Dirs: 0
 Dirperm1 Supported: true
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 4.0.9-boot2docker
Operating System: Boot2Docker 1.8.1 (TCL 6.3); master : 7f12e95 - Thu Aug 13 03:24:56 UTC 2015
CPUs: 1
Total Memory: 996.2 MiB
Name: default
ID: XLSE:62WR:VWCR:T2Z6:FSE3:NTLV:EQRT:WLW5:NLPF:HPQH:JQGR:K4LZ
Debug mode (server): true
File Descriptors: 9
Goroutines: 16
System Time: 2015-09-08T16:31:38.029737031Z
EventsListeners: 0
Init SHA1:
Init Path: /usr/local/bin/docker
Docker Root Dir: /mnt/sda1/var/lib/docker
Labels:
 provider=virtualbox

What I basically need is unbounded space for /dev/sda1, or to be able to specify a large disk size. I know this stems from my misunderstanding how docker mounts work, but I thought this thread would jump-start my research.

Thanks in advance.

回答1:

The option --virtualbox-disk-size needs to be entered in MB (see Docker Machine Docs). You created your machine with 4GB. This gives docker 2.8GB for storing images and running containers on /dev/sda1.

The default value for disk size, which is used by docker-machine create, is 20GB (according to docs linked above). Running docker images -a will show you how much disk space is required by the images you pulled. This will give you an indication how much more space you need.

Usually 20GB is a good size to pull several different images and run some containers. So maybe you create a new machine with the default disk size and try to import the mysql file again.