mirror of
https://github.com/containers/podman.git
synced 2025-06-20 09:03:43 +08:00
Merge pull request #20232 from umohnani8/ctr-create
Check for image with /libpod/containers/create
This commit is contained in:
@ -2,6 +2,7 @@ package libpod
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -13,6 +14,7 @@ import (
|
|||||||
"github.com/containers/podman/v4/pkg/specgen"
|
"github.com/containers/podman/v4/pkg/specgen"
|
||||||
"github.com/containers/podman/v4/pkg/specgen/generate"
|
"github.com/containers/podman/v4/pkg/specgen/generate"
|
||||||
"github.com/containers/podman/v4/pkg/specgenutil"
|
"github.com/containers/podman/v4/pkg/specgenutil"
|
||||||
|
"github.com/containers/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateContainer takes a specgenerator and makes a container. It returns
|
// CreateContainer takes a specgenerator and makes a container. It returns
|
||||||
@ -60,12 +62,20 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
warn, err := generate.CompleteSpec(r.Context(), runtime, &sg)
|
warn, err := generate.CompleteSpec(r.Context(), runtime, &sg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, storage.ErrImageUnknown) {
|
||||||
|
utils.Error(w, http.StatusNotFound, fmt.Errorf("no such image: %w", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rtSpec, spec, opts, err := generate.MakeContainer(r.Context(), runtime, &sg, false, nil)
|
rtSpec, spec, opts, err := generate.MakeContainer(r.Context(), runtime, &sg, false, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, storage.ErrImageUnknown) {
|
||||||
|
utils.Error(w, http.StatusNotFound, fmt.Errorf("no such image: %w", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -174,6 +174,10 @@ if root; then
|
|||||||
podman rm -f $CTRNAME
|
podman rm -f $CTRNAME
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Container create without existing image should return 404
|
||||||
|
t POST libpod/containers/create Image="foo" 404 \
|
||||||
|
.cause="image not known"
|
||||||
|
|
||||||
# Issue #6799: it should be possible to start a container, even w/o args.
|
# Issue #6799: it should be possible to start a container, even w/o args.
|
||||||
t POST libpod/containers/create?name=test_noargs Image=${IMAGE} 201 \
|
t POST libpod/containers/create?name=test_noargs Image=${IMAGE} 201 \
|
||||||
.Id~[0-9a-f]\\{64\\}
|
.Id~[0-9a-f]\\{64\\}
|
||||||
|
Reference in New Issue
Block a user