mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-08-10 02:45:44 +00:00
* Make context keys package safe * Add support for PODMAN_HOST and PODMAN_SSHKEY * Add slight increasing delay when client connections fail * Remove usages of path.Join(), added JoinURL(). '/' is not OS dependent. Signed-off-by: Jhon Honce <jhonce@redhat.com>
30 lines
779 B
Go
30 lines
779 B
Go
package containers
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/containers/libpod/pkg/api/handlers/utils"
|
|
"github.com/containers/libpod/pkg/bindings"
|
|
"github.com/containers/libpod/pkg/specgen"
|
|
jsoniter "github.com/json-iterator/go"
|
|
)
|
|
|
|
func CreateWithSpec(ctx context.Context, s specgen.SpecGenerator) (utils.ContainerCreateResponse, error) {
|
|
var ccr utils.ContainerCreateResponse
|
|
conn, err := bindings.GetClient(ctx)
|
|
if err != nil {
|
|
return ccr, err
|
|
}
|
|
specgenString, err := jsoniter.MarshalToString(s)
|
|
if err != nil {
|
|
return ccr, nil
|
|
}
|
|
stringReader := strings.NewReader(specgenString)
|
|
response, err := conn.DoRequest(stringReader, http.MethodPost, "/containers/create", nil)
|
|
if err != nil {
|
|
return ccr, err
|
|
}
|
|
return ccr, response.Process(&ccr)
|
|
}
|