Docker run -v foo:/foo/ initializes volume

Hi,
I’m trying to figure out how to use volumes to persist data for my container. I’m using Docker Desktop for Windows 4.14.1 over Engine Version: 20.10.21 on Windows 11 against Windows Containers.

  1. I’ve created a volume
    “docker volume create -d local --label srtdata --name srtdata”

  2. I then run my container and mount the volume

‘docker run myorg/myimage -v srtdata:C:/srtdata/’

which creates my new container using myimage (which is a windows-based image). This works great. I can Terminal to my running container and I can see there is C:\srtdata\

I then MKDIR c:\srtdata\foo\

this works great.

I then stop my container. Next I rerun the command

‘docker run myorg/myimage -v srtdata:C:/srtdata/’

which starts another container. I open Terminal, and "dir \srtdata' and it’s empty

Why don’t new containers preserve the data in my srtdata volume?

Thanks

The image name has to be the last parameter. Everything after that is the argument of the process running inside the container. Run docker run --help for more information.

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

Options:
...
  -v, --volume list                    Bind mount a volume
      --volume-driver string           Optional volume driver for the container
      --volumes-from list              Mount volumes from the specified container(s)
...

As you can see -v is an option and has to be before IMAGE

1 Like

Yep…that works. I knew it had to be something basic.

thanks!