1

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.

Vadzim
  • 21,258
  • 10
  • 119
  • 142
  • Deleting and recreating the container should be pretty routine, and it's better practice than trying to modify Docker internals. – David Maze Jan 03 '21 at 12:12
  • @DavidMaze Then you mean make container as image and using that image, make new container when I need new ports? Could you explain why it is better? Modify docker internal config may have a problem? – Yunseong Jeon Jan 03 '21 at 15:28

1 Answers1

1

Where it can be accessed

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

Where it is not (but may be expected)

That subdirectories of /mnt/wsl/docker-desktop-data/version-pack-data is 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$ 
Spastika
  • 11
  • 2