Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform on create #2551

Merged
merged 2 commits into from
Jun 11, 2020
Merged

Platform on create #2551

merged 2 commits into from
Jun 11, 2020

Conversation

cpuguy83
Copy link
Collaborator

- What I did
Set platform on container create API.

Previously we only set the platform when performing a pull, which is
only initiated if pull always is set, or if the image reference does not
exist in the daemon.

The daemon now supports specifying which platform you wanted on
container create so it can validate the image reference is the platform
you thought you were getting.

- How I did it
Propagate platform to the container create API

- How to verify it

Run engine master with DOCKER_API_VERSION=1.41

docker run --platform=linux/armhf busybox
docker run busybox

Before this change:
The 2nd run would run an armhf image somewhat unexpectedly.

After this change:
The 2nd run will do a new pull to get the host native arch (ie linux/amd64).

- Description for the changelog

Propagate platform flag to container create API

- A picture of a cute animal (not mandatory but encouraged)

imgpsh_mobile_save

This brings in client support to set the platform on container create.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
@thaJeztah
Copy link
Member

@cpuguy83 Looks like there's a build failure

cli/command/container/create_test.go:115:4: cannot use func literal (type func(*container.Config, *container.HostConfig, *network.NetworkingConfig, string) (container.ContainerCreateCreatedBody, error)) as type func(*container.Config, *container.HostConfig, *network.NetworkingConfig, *v1.Platform, string) (container.ContainerCreateCreatedBody, error) in field value
cli/command/container/create_test.go:184:4: cannot use func literal (type func(*container.Config, *container.HostConfig, *network.NetworkingConfig, string) (container.ContainerCreateCreatedBody, error)) as type func(*container.Config, *container.HostConfig, *network.NetworkingConfig, *v1.Platform, string) (container.ContainerCreateCreatedBody, error) in field value
cli/command/container/create_test.go:244:5: cannot use func literal (type func(*container.Config, *container.HostConfig, *network.NetworkingConfig, string) (container.ContainerCreateCreatedBody, error)) as type func(*container.Config, *container.HostConfig, *network.NetworkingConfig, *v1.Platform, string) (container.ContainerCreateCreatedBody, error) in field value
cli/command/container/create_test.go:280:3: cannot use func literal (type func(*container.Config, *container.HostConfig, *network.NetworkingConfig, string) (container.ContainerCreateCreatedBody, error)) as type func(*container.Config, *container.HostConfig, *network.NetworkingConfig, *v1.Platform, string) (container.ContainerCreateCreatedBody, error) in field value
cli/command/container/run_test.go:18:3: cannot use func literal (type func(*container.Config, *container.HostConfig, *network.NetworkingConfig, string) (container.ContainerCreateCreatedBody, error)) as type func(*container.Config, *container.HostConfig, *network.NetworkingConfig, *v1.Platform, string) (container.ContainerCreateCreatedBody, error) in field value
cli/command/container/run_test.go:58:4: cannot use func literal (type func(*container.Config, *container.HostConfig, *network.NetworkingConfig, string) (container.ContainerCreateCreatedBody, error)) as type func(*container.Config, *container.HostConfig, *network.NetworkingConfig, *v1.Platform, string) (container.ContainerCreateCreatedBody, error) in field value

Previously we only set the platform when performing a pull, which is
only initiated if pull always is set, or if the image reference does not
exist in the daemon.

The daemon now supports specifying which platform you wanted on
container create so it can validate the image reference is the platform
you thought you were getting.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Comment on lines +240 to +243
// Engine API version 1.41 first introduced the option to specify platform on
// create. It will produce an error if you try to set a platform on older API
// versions, so check the API version here to maintain backwards
// compatibility for CLI users.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change

cli/cli/command/utils.go

Lines 125 to 129 in 590f327

func AddPlatformFlag(flags *pflag.FlagSet, target *string) {
flags.StringVar(target, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
flags.SetAnnotation("platform", "version", []string{"1.32"})
flags.SetAnnotation("platform", "experimental", nil)
}
to restrict the option to API v1.41 and up?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Platform is supported on pull since I don't know when.

@thaJeztah
Copy link
Member

@tonistiigi ptal 🤗

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thaJeztah thaJeztah added this to the 20.03.0 milestone Jun 9, 2020
@tiborvass
Copy link
Collaborator

On moby I'm using master at a2282777c6 with this CLI, and I get:

$ ./build/docker run -it --rm --platform arm64 busybox
standard_init_linux.go:190: exec user process caused "no such file or directory"
$ cat > /tmp/foo.go
package main

import (
	"fmt"
	"runtime"
)

func main() {
	fmt.Println(runtime.GOARCH)
}
$ GOARCH=arm64 go run /tmp/foo.go # proof that aarch64 qemu is registered in binfmt
arm64

@cpuguy83
Copy link
Collaborator Author

cpuguy83 commented Jun 9, 2020

@tiborvass I'm not sure I'm following along, here is what I'm seeing:

root@b592547c5784:/go/src/github.com/docker/docker# docker rmi busybox:latest
Untagged: busybox:latest
Deleted: sha256:19d689bc58fd64da6a46d46512ea965a12b6bfb5b030400e21bc0a04c4ff155e
Deleted: sha256:7ce37844ca75600dbcbe085858845c5b92b6109db3c8c1ae6eb887aab91ad04f
root@b592547c5784:/go/src/github.com/docker/docker# docker pull --platform=amd64 busybox:latest
latest: Pulling from library/busybox
Digest: sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209
Status: Downloaded newer image for busybox:latest
docker.io/library/busybox:latest
root@b592547c5784:/go/src/github.com/docker/docker#  docker run -it --rm --platform=arm64 busybox sh
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
fd44016e3d3e: Pull complete
Digest: sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209
Status: Downloaded newer image for busybox:latest
standard_init_linux.go:211: exec user process caused "exec format error"

After setting up binfmt:

root@b592547c5784:/go/src/github.com/docker/docker#  docker run -it --rm --platform=arm64 busybox sh
/ #

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants