educative.io

The command did not create volume that does not exist

Hi there,

I am trying to follow the course for Docker Deep Dive: Advance Technique especially for the Mount Volume section (Demonstrating Volumes with Containers and Services)

It looks like the command below did not create a volume automatically.
$ docker container run -dit --name voltainer --mount type=bind,source=/usercode/bizvol,target=/vol alpine

It said in the content by running that command:

  • If you specify an existing volume, Docker will use the existing volume.
  • If you specify a volume that doesn’t exist, Docker will create it for you.

However, since the volume does not exist, Docker did not create the volume after running the command.

Does the correct command should be like this?
docker container run -dit --name voltainer --volume ./bizol:/vol alpine

it looks like if we are using mount it did not create the volume after running the command, however it will create one if we use volume instead.

Thanks


Course: Docker Deep Dive: Advanced Techniques - Learn Interactively
Lesson: Demonstrating Volumes with Containers and Services

Hi @wahyu_sumartha_priya!!
Based on the provided lesson content, the correct command for automatically creating a volume would indeed use the --volume flag instead of --mount:

docker container run -dit --name voltainer --volume ./bizol:/vol alpine

As mentioned in the lesson, when using --volume, Docker will create the volume if it doesn’t exist. This behavior is different from --mount, where Docker expects the volume to already exist.

So, if your goal is to automatically create a volume if it doesn’t exist, using --volume is the appropriate approach, as demonstrated in the lesson.
I hope it helps. Happy Learning :blush:

Hi @Javeria_Tariq

Thanks for your reply.

The part that caused some confusion is this one (attached screenshot). It was mentioned right after we were supposed to run the command with --mount. By using --mount options, we need to ensure that the directory exists.

It said:

In this case, bizvol didn’t exist, so Docker created it and mounted it into the new container. This means you’ll be able to see it with docker volume ls.