As I know, docker doesn't support any command that change port mapping after make container.
But this answer said that by changing the hostconfig.json file, I can change port mapping.
How do I assign a port mapping to an existing Docker container?
I'm using docker desktop in windows + WSL2.So path of hostconfig.json is different with other answers.
Where is hostconfig.json?
In my case, (\wsl$\docker-desktop-data\mnt\wsl\docker-desktop-data\data, /var/lib/docker(in wsl)) directories are not exist.
Trouble finding docker image storage folder You can find these folders by opening your WSL Linux distribution and entering: explorer.exe . to view the folder in Windows File Explorer. Enter: \\wsl\<distro name>\mnt\wsl replacing <distro name> with the name of your distribution (ie. Ubuntu-20.04) to see these folders.
ls -l /var/lib/docker/volumes/ Beta Was this translation helpful?
hostconfig.json
for a container can be found in WSL2 using Windows Explorer at the hidden network path \\wsl$\docker-desktop-data\version-pack-data\community\docker\containers\{containerid}\hostconfig.json
Windows Explorer Screenshot with hostconfig.json
The subdirectories of /mnt/wsl/docker-desktop-data/version-pack-data
are not exposed to WSL (for some reason):
deno@DeonJ-T570:/mnt/wsl/docker-desktop-data/version-pack-data$ sudo ls -al
[sudo] password for deno:
total 0
drwxr-xr-x 2 root root 40 May 25 12:09 .
drwxr-xr-x 6 root root 120 May 25 12:09 ..
deno@DeonJ-T570:/mnt/wsl/docker-desktop-data/version-pack-data$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With