aboutsummaryrefslogtreecommitdiff
path: root/libpod/image
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/image')
-rw-r--r--libpod/image/image.go10
-rw-r--r--libpod/image/image_test.go4
-rw-r--r--libpod/image/pull.go15
3 files changed, 26 insertions, 3 deletions
diff --git a/libpod/image/image.go b/libpod/image/image.go
index b5c4c537f..3863338b5 100644
--- a/libpod/image/image.go
+++ b/libpod/image/image.go
@@ -260,6 +260,12 @@ func (i *Image) getLocalImage() (*storage.Image, error) {
if hasReg {
return nil, errors.Errorf("%s", imageError)
}
+ // if the image is saved with the repository localhost, searching with localhost prepended is necessary
+ // We don't need to strip the sha because we have already determined it is not an ID
+ img, err = i.imageruntime.getImage(DefaultLocalRepo + "/" + i.InputName)
+ if err == nil {
+ return img.image, err
+ }
// grab all the local images
images, err := i.imageruntime.GetImages()
@@ -462,6 +468,10 @@ func (i *Image) TagImage(tag string) error {
if !decomposedTag.isTagged {
tag = fmt.Sprintf("%s:%s", tag, decomposedTag.tag)
}
+ // If the input doesn't specify a registry, set the registry to localhost
+ if !decomposedTag.hasRegistry {
+ tag = fmt.Sprintf("%s/%s", DefaultLocalRepo, tag)
+ }
tags := i.Names()
if util.StringInSlice(tag, tags) {
return nil
diff --git a/libpod/image/image_test.go b/libpod/image/image_test.go
index 71beed495..04877dbe5 100644
--- a/libpod/image/image_test.go
+++ b/libpod/image/image_test.go
@@ -170,12 +170,12 @@ func TestImage_MatchRepoTag(t *testing.T) {
// foo should resolve to foo:latest
repoTag, err := newImage.MatchRepoTag("foo")
assert.NoError(t, err)
- assert.Equal(t, "foo:latest", repoTag)
+ assert.Equal(t, "localhost/foo:latest", repoTag)
// foo:bar should resolve to foo:bar
repoTag, err = newImage.MatchRepoTag("foo:bar")
assert.NoError(t, err)
- assert.Equal(t, "foo:bar", repoTag)
+ assert.Equal(t, "localhost/foo:bar", repoTag)
// Shutdown the runtime and remove the temporary storage
cleanup(workdir, ir)
}
diff --git a/libpod/image/pull.go b/libpod/image/pull.go
index a5a398eb1..2eaa03858 100644
--- a/libpod/image/pull.go
+++ b/libpod/image/pull.go
@@ -46,6 +46,9 @@ var (
AtomicTransport = "atomic"
// DefaultTransport is a prefix that we apply to an image name
DefaultTransport = DockerTransport
+ // DefaultLocalRepo is the default local repository for local image operations
+ // Remote pulls will still use defined registries
+ DefaultLocalRepo = "localhost"
)
type pullStruct struct {
@@ -56,6 +59,14 @@ type pullStruct struct {
}
func (ir *Runtime) getPullStruct(srcRef types.ImageReference, destName string) (*pullStruct, error) {
+ imgPart, err := decompose(destName)
+ if err == nil && !imgPart.hasRegistry {
+ // If the image doesn't have a registry, set it as the default repo
+ imgPart.registry = DefaultLocalRepo
+ imgPart.hasRegistry = true
+ destName = imgPart.assemble()
+ }
+
reference := destName
if srcRef.DockerReference() != nil {
reference = srcRef.DockerReference().String()
@@ -149,7 +160,9 @@ func (ir *Runtime) getPullListFromRef(ctx context.Context, srcRef types.ImageRef
image := splitArr[1]
// remove leading "/"
if image[:1] == "/" {
- image = image[1:]
+ // Instead of removing the leading /, set localhost as the registry
+ // so docker.io isn't prepended, and the path becomes the repository
+ image = DefaultLocalRepo + image
}
pullInfo, err := ir.getPullStruct(srcRef, image)
if err != nil {