mirror of
https://github.com/containers/podman.git
synced 2025-06-19 08:09:12 +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 (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@ -13,6 +14,7 @@ import (
|
||||
"github.com/containers/podman/v4/pkg/specgen"
|
||||
"github.com/containers/podman/v4/pkg/specgen/generate"
|
||||
"github.com/containers/podman/v4/pkg/specgenutil"
|
||||
"github.com/containers/storage"
|
||||
)
|
||||
|
||||
// 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)
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
||||
rtSpec, spec, opts, err := generate.MakeContainer(r.Context(), runtime, &sg, false, 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)
|
||||
return
|
||||
}
|
||||
|
@ -174,6 +174,10 @@ if root; then
|
||||
podman rm -f $CTRNAME
|
||||
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.
|
||||
t POST libpod/containers/create?name=test_noargs Image=${IMAGE} 201 \
|
||||
.Id~[0-9a-f]\\{64\\}
|
||||
|
Reference in New Issue
Block a user