From 825c84efe1feaf95e63476db6b9c69510e1b87de Mon Sep 17 00:00:00 2001
From: Daniel J Walsh <dwalsh@redhat.com>
Date: Tue, 27 Apr 2021 09:22:32 -0400
Subject: [PATCH] Allow docker volume create API to pass without name

The Docker API does not require Volume name to be specified when
creating a volume.

Fixes: https://github.com/containers/podman/issues/9803

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
---
 pkg/api/handlers/compat/volumes.go | 16 +++++++++++-----
 test/apiv2/30-volumes.at           |  7 +++++++
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/pkg/api/handlers/compat/volumes.go b/pkg/api/handlers/compat/volumes.go
index d86fc1e19c..1ff1468e74 100644
--- a/pkg/api/handlers/compat/volumes.go
+++ b/pkg/api/handlers/compat/volumes.go
@@ -96,11 +96,17 @@ func CreateVolume(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	// See if the volume exists already
-	existingVolume, err := runtime.GetVolume(input.Name)
-	if err != nil && errors.Cause(err) != define.ErrNoSuchVolume {
-		utils.InternalServerError(w, err)
-		return
+	var (
+		existingVolume *libpod.Volume
+		err            error
+	)
+	if len(input.Name) != 0 {
+		// See if the volume exists already
+		existingVolume, err = runtime.GetVolume(input.Name)
+		if err != nil && errors.Cause(err) != define.ErrNoSuchVolume {
+			utils.InternalServerError(w, err)
+			return
+		}
 	}
 
 	// if using the compat layer and the volume already exists, we
diff --git a/test/apiv2/30-volumes.at b/test/apiv2/30-volumes.at
index 623e691e3b..ed606134aa 100644
--- a/test/apiv2/30-volumes.at
+++ b/test/apiv2/30-volumes.at
@@ -13,6 +13,13 @@ t POST libpod/volumes/create name=foo1  201 \
     .CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.* \
     .Labels={} \
     .Options={}
+t POST volumes/create 201 \
+    .Name~[0-9a-f]\\{64\\}
+    .Driver=local \
+    .Mountpoint=$volumepath/~[0-9a-f]\\{64\\}/_data \
+    .CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.* \
+    .Labels={} \
+    .Options={}
 t POST libpod/volumes/create 201
 t POST libpod/volumes/create \
   Name=foo2 \