Move docker images directory out of C drive on windows - docker

I have pulled few windows images from docker hub which are stored in my C-Drive by default. (C:\ProgramData\Docker)
Please explain how I can move those to a different drive like D.

The simplest solution is to move the directory to the intended location, and then create a directory junction from the old location to the new one:
move C:\ProgramData\Docker D:\mypath\Docker
mklink /j C:\ProgramData\Docker D:\mypath\Docker
this causes Docker to believe that the data is still at C:\ProgramData\Docker, even though it isn't, and it will not take up any space on C:.
You can find a few other solutions at https://github.com/docker/for-win/issues/185 , but it appears that they don't work 100%.

As described in the following article, worked for me in a Windows Server 2019 environment running Docker client and server version 20.10.7.
https://www.ntweekly.com/2019/09/20/how-to-change-docker-storage-data-folder-on-windows-server-2016/
Stop the docker service
stop-service docker
Edit following file, create it if not already there:
C:\ProgramData\Docker\config\daemon.json
Add data-root element to the json string:
{
"data-root": "e:\\DockerData"
}
Restart the service:
restart-service docker
Beware, your images and containers aren't automatically moved to the new location, you need to manually relocate them.

Related

Is it possible if I want to change my docker data-root directory to another server?

I installed docker inside of a server or what I usually called as a VM (Virtual Machine, with RHEL environment) and I have been thinking of using a new directory in a remoted Windows network as my new data-root directory (due to space reason).
In my case, the data-root directory from my VM located at /home/docker_new and the path where I want to use as a new data-root directory from the remote Windows network is for example, at
\\xx.xx.x.x\a\b\c.
I did try to make my research and finds that most of the solutions are all focusing on changing the data-root directory within the same VM. Some focusing on how to 'move' the docker to another server. While what I intended to do is just to change the data-root directory to another directory in a remoted windows network .
So, my question is:
1. Is it possible to do so?
2. If its possible, what are the steps that I should follow?

Process can write to docker volume on Windows not on Ubuntu

I have an image based on opencpu/base. It starts an apache based server, and then invokes R scripts everytime sombody calls an API endpoint.
One of those scripts tries to write a file to a location in the container. When I mount a folder into that location, it works on my Windows machine, but not on Ubuntu.
I've tried using named volumes on Ubuntu, but it does not work either. When I run bash inside the container interactively on Ubuntu, I can write and read the mounted volume just fine. But the apache process cannot.
Does anybody have some hints what could be going on here?
When you log in interactively to the container, you will have root permissions.
Apache usually runs as another user (www-data), and that user must have read permissions on the folder that you want it to read.
Make sure that the permissions of the folder matches the user that will read it.

Docker-compose volumes not mounted correctly in VirtualBox under Windows

I am trying to run Hyperledger's BYFN Tutorial on a Win10 Home using Docker Toolbox, with VirtualBox 5.2.4. I am using the default image for the VirtualBox VM.
I have set up a shared folder (not in C:/Users, but on my other drive) and it seems to be functioning correctly - changes I make from either Windows, or the docker-machine are reflected in both places as intended. I successfully generate the network artifacts using "./byfn -m generate", but I get an error when trying to "./byfn up" it.
What happens is that, as far as I can see from the logs, all the containers get brought up correctly, but for some reason the volumes of the cli container are not attached correctly (I think). When byfn.sh finishes I get the following error:
When I ssh into the cli container, I can see the channel-artifacts, crypto and scripts folders, but their contents don't seem to correlate with the volumes: part of the docker-compose file. First, the scripts folder is empty (whereas in the docker-compose file it's specified that it should mount a bunch of files), so I get the above error. Second, the channel-artifacts containes only 1 directory named genesis.block, which should actually be a file. And in the crypto folder there are just a bunch of directories.
As you might have guessed, I'm pretty new at docker, so this might be intended behavior, but I'm still getting an error.
Please let me know if I can provide additional information. Thanks in advance.

Docker won't change VHD location

So I am running on win10 with Hyper-V.
Docker is currently using a harddrive instance thats stored on my C drive (which is an ssd with very little space) I want it on my sshd which is my D drive.
The following is what I tried and has failed, because it looks like Docker just jumps back to its default every time.
change is using the docker interface in the advance section (to a copy of the vhdx file in the d drive)
changing it manually in the hyperv manager by having it migrate the harddrive to a new location
As well as other variations where I restart my computer after doing these.
Use docker > settings > advanced > change vhd location. Notice, you should select an empty directory instead of copy the VHD file by yourself.
Stop / Shutdown Docker
Copy/Move the existing .vhdx from
C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\MobyLinuxVM.vhdx
to
D:\MobyLinuxVM.vhdx (your preferred ssd location)
Edit the Docker settings.json file (%APPDATA%\Docker\settings.json) and configure
"MobyVhdPathOverride": "D:\MobyLinuxVM.vhdx"
Now start the Docker again - the changes should be in place.
When I was having similar problems in that simply changing the Disk image location path would not stick upon a docker restart; this process worked for me:
Create the destination folder, make sure its empty (so no copies of MobyLinuxVM.vhdx)
In Docker>Reset>Restore to factory defaults... restore your docker to factory defaults
In Docker>Settings>Shared Drives give the drive( in your case, D) shared access to docker. Hit apply.
In Docker>Settings>Advanced browse under Disk image location to your destination folder. Hit Apply.
ref: https://github.com/docker/for-win/issues/2063
This is DockerDesktop verison 4.7.1.
Click on the docker icon on the taskbar and go to settings or right click the docker icon on the taskbar and select settings. The window below will popup.
Navigate to the Resources on the left pane and scroll down (if Disk Image Location is not in view). Click on Browse and select an empty folder of your choice. Click on Apply and Restart and Docker Desktop will move the .vhdx from C:\Users\Public\Documents\Hyper-V\Virtual hard disks to your select folder.
If Docker Desktop encounters an error, close Docker Desktop and navigate to C:\Users\<User>\AppData\Roaming\Docker\settings.json and edit the "dataFolder": "D:\\Hyper-V\\Virtual hard disks\\DockerDesktop", to your destination folder. Restart Docker Desktop.

Change Docker native images location on Windows 10 Pro

This is not a duplicate of Change Docker machine location - Windows
I'm using docker native, version 1.12.1-stable (build: 7135) on Windows 10 Pro with Hyper-V enabled.
So docker is not running with VirtualBox nor do I have the folder C:\Users\username\.docker
I'd like to move docker's images, caches, ... to my secondary drive D:\
I guess I should edit the Docker Daemon configuration.
I tried to add "graph": "/D/docker". Docker started correctly but I couldn't pull any image because of an error
open /D/docker/tmp/GetImageBlob135686954: no such file or directory
How to tell docker to use another path to store its images, etc ?
Docker Desktop now can use WSL 2 Backend. In this mode, you need to move the wsl data.
In my case (Windows10 with Docker Desktop) none of the above solutions helped me, but I found the solution; run these commands.
This command changes the docker directory to drive D: (don't forget to quit docker desktop first)
wsl --shutdown
wsl --export docker-desktop-data docker-desktop-data.tar
wsl --unregister docker-desktop-data
wsl --import docker-desktop-data D:\docker-new-repo\ docker-desktop-data.tar --version 2
And now you can delete .tar file
There is a very good blog post explaining everything:
https://dev.to/kimcuonthenet/move-docker-desktop-data-distro-out-of-system-drive-4cg2
Docker Version : 2.2.0.3 (42716)
Right-click on docker icon on desktop tray
Click on Settings
3 Click on Resources from the left-hand menu then under the Disk Image location click on browse and change the location
Click on apply and restart
In 2020 to "Change Docker native images location on Windows 10 Pro" is:
quit docker desktop
open/edit configuration file C:\ProgramData\Docker\config\daemon.json
add setting "data-root": "D:\\Virtual Machines\\Docker"
now start docker desktop
run the command docker info to see the setting Docker Root Dir: D:\Virtual Machines\Docker
pull docker images e.g.: docker pull mongo
you can find the downloaded images in folder D:\Virtual Machines\Docker\windowsfilter
I found a solution here
Docker native, on Windows, runs in a Hyper-V virtual machine.
Move existing docker VM
I have to move the VM used by docker to the desired location.
I did this using the GUI of Hyper-V manager.
The VM for docker is called MobyLinuxVM.
Right-click MobyLinuxVM
Select Move
Select desired location
Set location of futures Hyper-V VMs
And to be sure futures VMs of Hyper-V will be stored on my secondary drive,
I followed those instructions
In a powershell terminal (destination folders must exist)
SET-VMHOST –computername <computer> –virtualharddiskpath 'D:\Hyper-V_Virtual-Hard_Disks'
SET-VMHOST –computername <computer> –virtualmachinepath 'D:\Hyper-V_VMs'
Edit the Docker Daemon configuration and use "data-root": "D:\\docker" instead of "graph": "/D/docker".
That will move all the newly downloaded images to D:\docker folder.
For Old Docker version use graph "graph": "D:\\docker", "graph" has been deprecated.
There is an easier way to do this:
Go to Docker Settings > Advanced > Change "Disk image location" and click "Apply" when prompted. Docker engine will shut down the VM and move it for you to the new location.
Warning: new location must not be compressed. If it is then Docker will not show you any error, just won't change location.
None of these steps worked for me. After reboot or a Docker restart, it would move back to the original path. What worked for me is using Junction
stop docker engine
create a target folder in the new location:
mkdir d:\docker\vhd
copy the folder Virtual Hard Disks to the target folder
rename (and backup) the original folder
rename “C:\Users\Public\Documents\Hyper-V\Virtual hard disks” “C:\Users\Public\Documents\Hyper-V\Virtual hard disks_backup”
create a hard symbolic link (junction)
junction.exe "C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks" "d:\docker\vhd\Virtual Hard Disks"
start docker engine
For Those looking in 2020. The following is for Windows 10 Machine:
In the global Actions pane of Hyper-V Manager click Hyper-V
Settings…
Under Virtual Hard Disks change the location from the default to
your desired location.
Under Virtual Machines change the location from the default to your
desired location, and click apply.
Click OK to close the Hyper-V Settings page.
If issues using the Docker Desktop GUI, when using Hyper-V:
Shutdown Docker Desktop
Edit c:\users\[USERNAME]\AppData\Roaming\Docker\settings.json
You need to edit dataFolder entry. Use Double backslashes.
eg: "dataFolder": "D:\\Demo\\Hyper-V\\DockerDesktop\\DockerDesktop"
Restart Docker Desktop
You can also use the above if Docker Desktop loses track of where you data folder is, as the GUI doesn't allow you to set it to a previously used location.
I would recommend looking at Microsoft documentation docker engine on windows, it's the daemon.json file that allows to change the setting "data-root": "".
From: https://github.com/microsoft/WSL/issues/4699#issuecomment-658369676
He created a symlink pointing to the new folder location. By running:
$ErrorActionPreference = "Stop"
$newLocation = "E:\VMs\WSL2\"
cd "~\AppData\Local\Docker\wsl\data"
wsl --shutdown
Optimize-VHD .\ext4.vhdx -Mode Full
mkdir $newLocation -Force
mv ext4.vhdx $newLocation
cd ..
rm "data"
New-Item -ItemType SymbolicLink -Path "data" -Target $newLocation
He also wrote a blog post going into more detail: http://nuts4.net/post/moving-wsl2-vhdx-file-to-a-different-location
Just configuration from Docker Desktop worked for me (Latest Version V20.10.8)
Steps
Go to settings
Select 'Docker Engine' option
Add property "data-root": "D:\\Docker" in configuration file
Apply and Restart
Settings

Resources