LewlSauce
LewlSauce

Reputation: 5892

Can't run Docker commit, not enough space

I'm fairly new to Docker and still trying to understand some of the basic things. At the moment, I have two Docker images:

[root:kali:~]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
kalilinux/kali-linux-docker   latest              5e4d6c84829d        About an hour ago   9.57GB
kalilinux/kali-linux-docker   <none>              f26f3ae90aee        2 months ago        1.57GB

For whatever reason, the first one with the latest tag is a child of the other one. Assuming the one with the latest tag is a container that I committed changes to.

However, now I'm trying to commit/save changes to this image, but I'm getting the following error:

Error response from daemon: Error processing tar file(exit status 1): write /usr/lib/x86_64-linux-gnu/libclang-7.so.1: no space left on device

I checked my disk space, and it looks like I have 4GB available:

[root:kali:~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            481M     0  481M   0% /dev
tmpfs            99M  944K   98M   1% /run
/dev/vda1        25G   20G  4.1G  83% /
tmpfs           493M     0  493M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           493M     0  493M   0% /sys/fs/cgroup
/dev/vda15      105M  3.6M  101M   4% /boot/efi
/dev/loop0       88M   88M     0 100% /snap/core/5662
/dev/loop1       67M   67M     0 100% /snap/lxd/9239
tmpfs            99M     0   99M   0% /run/user/0
overlay          25G   20G  4.1G  83% /var/lib/docker/overlay2/b2178e65852a017f21124a23d63e32a66faaa8b8375429865e8433da9fc0db20/merged
shm              64M     0   64M   0% /var/lib/docker/containers/af2d2ed99d91d2247f550a23af988ce4a624e186ac80782046f0868418547d3d/mounts/shm
/dev/loop2       90M   90M     0 100% /snap/core/6130
/dev/loop3       52M   52M     0 100% /snap/lxd/9795

So here are my questions:

  1. Is there any way that I can merge my two images so that I don't end up with a bunch of child images?
  2. Is the docker commit command actually trying to make a copy of the container? Or is it just simply saving it? My reason for this question is because I only have 4GB remaining, but yet I have the image exactly how I want it, so why can't it just save? Is it going to need an extra 9GB of space every time I run commit?

I am trying to avoid having to shut down the VPS and increase its disk space if I can help it.

Upvotes: 2

Views: 1280

Answers (1)

user934801
user934801

Reputation: 1139

As far as I know, there is no way to merge images, but deleting them is possible. With every commit you increase the size of your image. You can have a look into the layers of an image and their size with:

docker history <image name>

Instead of working with the old images you could use a Dockerfile and build the image you want to use from scratch. Building sometimes takes a longer time, but you should find a way to build the images in an automated way to be able to repeat them for production usage. If you build the images from scratch, and use some verified images you'll get the new patched version for free. Within a Dockerfile you can have a maximum of 125 layers, which means you should use as less RUN commands as possible and chain them with linux/unix notation e.g.

RUN apt-get update -y && apt-get install -y \
  ansible \
  openssh-client \
  vim \
  wget

https://docs.docker.com/engine/reference/builder/

https://github.com/dockerfile/ubuntu/blob/master/Dockerfile

Upvotes: 1

Related Questions