Jump to content

How-To: Shrinking Docker Image


Recommended Posts

I couldn't find any information on how to resize the image without destroying the one currently used (which would require reinstalling all the containers). So I used my Google-fu to see if there was anything on the interwebs but couldn't find anything relating to images, just partitions, but I figured I'd give it a try since I had backed up the original. You can do the first two steps while the image is mounted and it doesn't matter is you specify the mount point (/var/lib/docker) or the image itself (/mnt/user/system/docker/docker.img)

 

Step 1: Check the image's filesystem for errors

btrfsck -p --repair /mnt/user/system/docker/docker.img

 

Step 2: Resize the filesystem

btrfs filesystem resize [new size] /mnt/user/system/docker/docker.img

 

UNMOUNT THE IMAGE

 

Step 3: Resize the image itself

dd if=/mnt/user/system/docker/docker.img of=/mnt/user/system/docker/docker.img.new bs=2M count=6000 status=progress

 

The above command will resize the image to 12 GB (2 MB block size, 6,000 blocks is about 12,000 MB/12 GB)

 

Step 4: Make sure the image mounts

mount /mnt/user/system/docker/docker.img.new /var/lib/docker; ls /var/lib/docker

 

You should see the Docker filesystem in /var/lib/docker, now just unmount the image and either delete or rename the old docker.img and rename docker.img.new to docker.img and you're done!

Edited by brando56894
Link to comment
8 minutes ago, brando56894 said:

I couldn't find any information on how to resize the image without destroying the one currently used (which would require reinstalling all the containers).

Ugh...  Very, very simple to enlarge the image

 

https://forums.lime-technology.com/topic/57181-real-docker-faq/#comment-565307

 



How do I increase the size of my docker.img file?

 

Go to settings - Docker Settings.

 

Set Enable Docker to be "No"

 

Apply.

 

Switch to Advanced View (Top Right)

 

Change the size of the image.

 

Set Enable Docker to be "yes"

 

Apply

 

Done.

 

Link to comment

You completely missed the point of the post @Squid did you even read it? I changed the title because I'm assuming you just glanced at the title and went "ugh, silly noobs" and just copied that from your FAQ.

 

I'm doing the exact opposite of that, this was due to me increasing the size to 50 GB using the method posted above when I was trying to figure out why my image was running out of space, and once I did I found out that my containers took up about 5 GB worth of space in the image, yet it was taking up 50 GB on my cache drive.

 

Edit: you beat me to it haha

Edited by brando56894
Link to comment
Just now, brando56894 said:

You completely missed the point of the post @Squid did you even read it? I changed the title because I'm assuming you just glanced at the title and went "ugh, silly noobs" and just copied that from your FAQ.

 

I'm doing the exact opposite of that, this was due to me increasing the size to 50 GB using the method posted above when I was trying to figure out why my image was running out of space, and once I did I found out that my containers took up about 5 GB worth of space in the image, yet it was taking up 50 GB on my cache drive.

 

Edit: you beat me to it haha

Yeah, I think the original title didn't specify shrink, so yes I glanced, looked at the headache, and posted.

 

But, even there its still probably easier to just delete the image, and redownload the apps.  30 seconds later with no template changes required you're back in business.  But it is kinda cool to know how to do a shrink via the command line.

Link to comment
Just now, Squid said:

Yeah, I think the original title didn't specify shrink, so yes I glanced, looked at the headache, and posted.

 

Haha I know the feeling, I work in IT and have been a member of the FreeNAS forums (and other Linux forums) for years and usually do the same :) And yes I did change the title because it wasn't descriptive enough.

 

2 minutes ago, Squid said:

But, even there its still probably easier to just delete the image, and redownload the apps.  30 seconds later with no template changes required you're back in business.

 

I have 12 containers setup, so it would probably take like 5 minutes to setup all the paths and containers again, not a big deal but still something I would like to avoid if at all possible.

Link to comment
 
I have 12 containers setup, so it would probably take like 5 minutes to setup all the paths and containers again, not a big deal but still something I would like to avoid if at all possible.
You never need to reset up the paths. Via the docker tab you can add a template (select the my user template) everything will be filled out for you.

Under the apps tab go to previous apps and reinstall. Same thing all your paths are already filled out.

Under 6.4 with the apps tab you can check off multiple apps at a time then install them all with one button press with no interaction needed at all from the previous apps section

Sent from my LG-D852 using Tapatalk

  • Upvote 1
Link to comment

Just going to add my 2 bits:

When you shrink, you should ensure that the size you give in the filesystem shrink command is a bit smaller than the resulting size from your DD command. otherwise, you run the risk of truncating the filesystem and destroying it.

 

I've had to redo vm image copies over a WAN before when we did some shrinking and we ended up with disks/partitions that were truncated by a few sectors at the end. ugh.

 

  • Upvote 1
Link to comment
  • 9 months later...
On 8/15/2017 at 6:27 PM, Squid said:

But, even there its still probably easier to just delete the image, and redownload the apps.  30 seconds later with no template changes required you're back in business.  But it is kinda cool to know how to do a shrink via the command line.

 

Can you explain a bit more what I'll need to do. What about all my docker settings? Do I need to re-do all of them. It took me ages to configure musicbrainz docker et al. Will this be impacted?

Link to comment
12 hours ago, steve1977 said:

 

Can you explain a bit more what I'll need to do. What about all my docker settings? Do I need to re-do all of them. It took me ages to configure musicbrainz docker et al. Will this be impacted?

Nope.  All of your appdata remains intact.

Link to comment
  • 5 months later...

I had just posted a question about resizing the docker.img on Reddit a few minutes ago, then stumbled on this thread

 

It seems the "right" way to do this is to actually delete the dockers, then the image, then reset the image size, then reinstall the dockers? I'm confused as to how all my settings remain etc though?

Link to comment
  • 3 weeks later...
On 11/19/2018 at 3:10 PM, jpotrz said:

It seems the "right" way to do this is to actually delete the dockers, then the image, then reset the image size, then reinstall the dockers? I'm confused as to how all my settings remain etc though?

All your settings are stored in your appdata share, which is separate to the docker image (and likely on your cache drive).  The configuration of each docker (eg, the ports and shares it can access) are remembered by unraid as templates.

 

Theoretically, the only thing in the docker image file are the dockers themselves, and once installed should only change when new versions are downloaded - everything else that changes is in appdata*

 

* not always the case - log files can be in docker containers, as can data if a docker's been misconfigured.

 

 

Came here looking for the best way to shrink your image file (after I raised it whilst tracking down a problem).  Didn't know you could batch install with Community Applications.  Result!

Link to comment
  • 1 year later...
Label: none
uuid: 47d2ad00-2f07-4eeb-a68f-448568ed8f73
Total devices 1 FS bytes used 3.97GiB
devid 1 size 20.00GiB used 5.52GiB path /dev/loop2

I guess I could shrink a lot. Can I do this through Settings/Docker already or do I still have only those two options, Terminal or deleting and reinstalling apps?

Edited by mizifih
typo
Link to comment
53 minutes ago, Squid said:

^^ This.  But, I wouldn't worry about it with a 20G docker.img file

Yes, it's not like 20GB is too much, but my cache is always being filled so fast. It's probably Deluge, since I'm re-downloading a lot of stuff. I'll see how it's going to behave once all the torrenting slows down, but I think I'll have to squeeze a few GB wherever I can if this trend continues. I have a 250GB m.2 drive as cache.

Link to comment
  • 2 months later...

I know this is a older thread, but my docker.img is also 50GB and I wanted to shrink it, but I get an error.  I tried it both with the docker mounted and unmounted.  my docker takes uses only 6GB and wanted to shrink it to 10GB. is their a new way of doing this or any suggestions?  Thanks in advanced.

_________

Label: none uuid: f49bb50d-4601-4f39-8969-7fe3ac318b0a

Total devices 1 FS bytes used 4.45GiB

devid 1 size 50.00GiB used 6.07GiB path /dev/loop2

_________

 

btrfs filesystem resize 10GB /mnt/cache/docker.img

 

ERROR: resize works on mounted filesystems and accepts only
directories as argument. Passing file containing a btrfs image
would resize the underlying filesystem instead of the image.

Link to comment
  • 3 years later...

Welp...I lost all my docker networks when I tried deleting the docker img file and then recreating...hope no one else had to go through and manually setup all their docker containers again like me. I'd rather just do the original shrink method. Wish it was done in the Web GUI when you change the docker vdisk size option.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...