Go client: create container using image alias

WIth the old Go client, we used to be able to create a container via:

client.Init(name, "images", "ubuntu/xenial", ...)

Now I’m porting to the new client, but this does not seem to work:

 req := api.ContainersPost{
	Name: name,
	Source: api.ContainerSource{
		Type:       "image",
		Alias:      "ubuntu/xenial",
		Source:     "https://images.linuxcontainers.org",
op, err := d.client.CreateContainer(req)

The response is simply:

{"error": "not found"}

It works when I specify the fingerprint instead of the alias. Unfortunately documentation is a bit sparse, any hints?

A pretty simple trick with recent LXD is to pass “–debug” to the client.

DBUG[09-27|17:42:32] Sending request to LXD                   etag= method=POST url=http://unix.socket/1.0/containers
		"architecture": "",
		"config": null,
		"devices": {},
		"ephemeral": false,
		"profiles": null,
		"stateful": false,
		"description": "",
		"name": "xenial",
		"source": {
			"type": "image",
			"certificate": "",
			"alias": "ubuntu/xenial",
			"server": "https://images.linuxcontainers.org",
			"protocol": "simplestreams",
			"mode": "pull"
		"instance_type": ""

So I think the issue is that you didn’t set “protocol” which caused LXD to default to its native protocol. The remote image server supports that too, but then the alias is “ubuntu/xenial/amd64” rather than “ubuntu/xenial” which is only valid with simplestreams.

Thanks, that’s it. Also, I used source instead of server to specify the image server, which did work with a fingerprint, so no idea what’s the difference here. (edit: Just realized source is probably something completely different, because I already have the image with the fingerprint on disk). Some more documentation of the types in shared/api would be lovely. :slight_smile:

This works as expected:

	req := api.ContainersPost{
		Name: name,
		Source: api.ContainerSource{
			Type:     "image",
			Alias:    "ubuntu/xenial",
			Server:   "https://images.linuxcontainers.org",
			Protocol: "simplestreams",

	op, err := d.client.CreateContainer(req)