Docker won't change VHD location - docker

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.

Related

Move docker desktop data folder (windows containers)

I'm using docker desktop (4.X) over win10 pro. We are building Windows applications and using Windows containers.
On our setup, the folder C:\ProgramData\Docker(images/windowsfilter/tmp & co) can grow up to hundreds of GB, and i need to move this folder to an alternative location.
Again, i am using WINDOWS CONTAINERS (i do not care about wsl2 or hyper-v specific solutions)
I tried moving / creating a junction between
C:\ProgramData\ Docker => D:\DockerData, but windows containers backend does not start.
If i switch back to linux containers, everything is working fine (and i know how to move WSL2 vhdx, if needed, but again, i DO NOT NEED THAT information).
Moving HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\ProgramData location BEFORE installing docker desktop, works, but it is not an acceptable solution
I tried configuring data-root directory in %USERPROFILE%.docker\windows-daemon.json, But it does not work, windows containers backend does not start.
Please give me a reliable way to move the C:\ProgramData\Docker folder to another location.
Unfortunately, when utilizing Windows Containers, it is not yet feasible to relocate the C:ProgramDataDocker folder to another location. This is so that container images and other data can be stored in this directory, which the Docker for Windows service is hard-coded to utilize.
You might try using a symbolic link to reroute the C:ProgramDataDocker folder to an other place as a solution. This may not be a reliable approach, though, as the Docker for Windows service might not handle the symbolic link correctly, which would prevent the service from starting.

How to make VSCode forget about an old docker container?

I ran docker container prune, but after attaching it to my new container, I still see the old container in the explorer pane in VSCode. And I do not see the new container in the explorer pane.
And if I try to open a new terminal (Terminal > New Terminal), I see:
The terminal process failed to launch: Starting directory (cwd)
"/path/inside/my/old/container" does not exist.
Whenever I create a new container based on the same image (drupal:latest), VSCode tries to open the old container based on this image, even if I give the new container a different name.
VSCode also sometimes shows the error "Workspace does not exist" when I attach it to the new container.
After attaching to the new container, I needed to do...
File > Open Folder
And then, in the Open Folder UI, I needed to edit the old path there, which still referred to the old container, and then click OK.
For example, in the new container, the path /opt exists, so entered that path and clicked OK. This causes the explorer to refresh and the old container disappears and now I can access the new container. I can also open the terminal now.
0
I succeeded in connecting to a remote server configured with Docker through vscode. By the way, the list of containers from the past was fetched from the remote explorer of vscode. If you look at this list of containers, they are obviously containers made with images I downloaded a few days ago. I don't know why this is happening.

VSCode how to open a local folder within a local docker container.....without devcontainers.json?

I want start a docker container that I have created, and then mount a local folder to it in a way that doesn't make use of a devcontainers.json file. This is because I would like to test the same local repo out with multiple docker containers and editing the devcontainers.json file is a pain because I have to edit every time I want to change the docker image - where really I just want to do something like:
Dev Containers: Open Local Folder in Container
Choose Local Folder
Choose a docker container that is already running
The problem is that in step 3 I only see options to choose from pre-made base images i.e. Ubuntu 22.04. I can't see anywhere in the list any of my docker containers that I am running. Have I missed any functionality? Does what I'm asking exist......or must I use a devcontainers.json file?
If I correctly understood your issue:
Once you install Microsoft's Docker extension from the VS Code extensions' tab (ctrl + shift + x), you'll be able to do that.
This extensions have a "CONTAINERS" tab, where you can open another VSCode window inside a selected container's directory or attach a terminal to the container and manage the system.
Just right-click on the desired container and you'll see the options.

Move docker images directory out of C drive on windows

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.

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