Cannot launch container in a project on ubuntu 20.04 cluster

Recently setup a new cluster with Ubuntu 20.04 and using LXD snap 4.4.

Created a project with:

lxc project create testproject -c features.profiles=false -c features.images=true -c features.storage.volumes=false

lxc launch ubuntu:20.04 testcontainer1 --project testproject

Creating testcontainer1
Error: Failed instance creation: Create instance from image: open /var/snap/lxd/common/lxd/images/97c470e427c425cf2ec4d7d55b6f1397ea55043c518b194a58fc6b9da426f540: no such file or directory

lxc image list --project testproject

+-------+--------------+--------+---------------------------------------------+--------------+-----------+----------+------------------------------+
| ALIAS | FINGERPRINT  | PUBLIC |                 DESCRIPTION                 | ARCHITECTURE |   TYPE    |   SIZE   |         UPLOAD DATE          |
+-------+--------------+--------+---------------------------------------------+--------------+-----------+----------+------------------------------+
|       | 97c470e427c4 | no     | ubuntu 20.04 LTS amd64 (release) (20200804) | x86_64       | CONTAINER | 355.16MB | Aug 20, 2020 at 2:30pm (UTC) |
+-------+--------------+--------+---------------------------------------------+--------------+-----------+----------+------------------------------+

sudo ls -l /var/snap/lxd/common/lxd/images

-rw-r--r-- 1 root root       804 Aug 20 02:26 97c470e427c425cf2ec4d7d55b6f1397ea55043c518b194a58fc6b9da426f540
-rw-r--r-- 1 root root 372408320 Aug 20 02:26 97c470e427c425cf2ec4d7d55b6f1397ea55043c518b194a58fc6b9da426f540.rootfs

zfs list

local/images/97c470e427c425cf2ec4d7d55b6f1397ea55043c518b194a58fc6b9da426f540   533M  4.87T      533M  /var/snap/lxd/common/lxd/storage-pools/local/images/97c470e427c425cf2ec4d7d55b6f1397ea55043c518b194a58fc6b9da426f540

Not sure why image cannot be found.

Possibly an issue with a particular cluster node, can you try selecting a specific one with --target?

It does work with --target, it seems there is a problem with cluster in 4.4, this worked fine with 4.3 without specifying the target.

Any solution to this problem?

In our setup I create my own images regularly and the entire code for it does not specify --target, but it seems if this is mandatory than need to change the code.

It sounds like LXD thinks the image got replicated to that node but it’s somehow missing from the filesystem.

lxd sql global "SELECT * FROM nodes;"
lxd sql global "SELECT * FROM images;"
lxd sql global "SELECT * FROM images_nodes;"

Should be useful to figure out whether LXD thinks that particular node has the image, then if it’s missing from /var/snap/lxd/images/ then that’s certainly a problem. You can fix it easily enough by dropping the incorrect DB row, though understanding the condition that causes the DB entry to show up without the matching image making it to disk would be useful.

I fixed the issue by dropping the image and than use lxc image copy ubuntu:20.04 local: on the node where the image was giving error.

If this problem comes again will check the dB and update.

Having the same issue as above after deleting the image ubuntu:20.04, so checked the sql entries. In spite of deleting the image it still exist in list probably some conflict between image in project vs image in default project.

After further investigation can replicate the error consistently:

# create a test container in test project from ubuntu:20.04 the image has not been downloaded yet in default or specific project.

$  lxc launch ubuntu:20.04 test1 --project testproject

# It launches correctly and shows ubuntu image in list.

$ lxc list --project testproject

+------------------+---------+--------------------+------+-----------+-----------+-----------+
|       NAME       |  STATE  |        IPV4        | IPV6 |   TYPE    | SNAPSHOTS | LOCATION  |
+------------------+---------+--------------------+------+-----------+-----------+-----------+
| test1            | STOPPED |                    |      | CONTAINER | 0         |test-node-1| 
+------------------+---------+--------------------+------+-----------+-----------+-----------+

$ lxc image list --project testproject

+--------------------------+--------------+--------+---------------------------------------------+--------------+-----------+-----------+-------------------------------+
|          ALIAS           | FINGERPRINT  | PUBLIC |                 DESCRIPTION                 | ARCHITECTURE |   TYPE    |   SIZE    |          UPLOAD DATE          |
+--------------------------+--------------+--------+---------------------------------------------+--------------+-----------+-----------+-------------------------------+
|                          | aedb5a84aaf2 | no     | ubuntu 20.04 LTS amd64 (release) (20200907) | x86_64       | CONTAINER | 354.73MB  | Sep 14, 2020 at 9:40am (UTC)  |
+--------------------------+--------------+--------+---------------------------------------------+--------------+-----------+-----------+-------------------------------+

$ lxc image list

+-------------+--------------+--------+---------------------------------------------+--------------+-----------+----------+------------------------------+
|    ALIAS    | FINGERPRINT  | PUBLIC |                 DESCRIPTION                 | ARCHITECTURE |   TYPE    |   SIZE   |         UPLOAD DATE          |
+-------------+--------------+--------+---------------------------------------------+--------------+-----------+----------+------------------------------+
|             | aedb5a84aaf2 | no     | ubuntu 20.04 LTS amd64 (release) (20200907) | x86_64       | CONTAINER | 354.73MB | Sep 14, 2020 at 9:40am (UTC) |
+-------------+--------------+--------+---------------------------------------------+--------------+-----------+----------+------------------------------+

# now try to create container in default project

$ lxc launch ubuntu:20.04 test1
Creating test1
Error: Failed instance creation: Create instance from image: open /var/snap/lxd/common/lxd/images/aedb5a84aaf2e4e443e090511156366a2800c26cec1b6a46f44d153c4bf04205: no such file or directory

Please check the project settings in YAML file:

### Note that the name is shown but cannot be changed

description: ""
config:
  features.images: "true"
  features.profiles: "false"
  features.storage.volumes: "false"
name: testproject

Based on this experiment it looks like when images are shared first it needs to be downloaded in default project and than only subsequent project can use it. If the image is downloaded directly in project it cannot be shared among projects even though features.images: "true" is set.

@tomp can you take a look at this one too? :slight_smile:

I’m not sure how many tests we have for image copies / caching between nodes and across projects. I also know we have startup logic to delete any image artifacts that are not present in the DB, so maybe that’s misfiring too?

@stgraber taking a look now.

Reproduced the issue. Thanks.

It seems that the issue is that when the 2nd container is being created, it is placed on a different node than the first container, but thinks it is available locally due to lxc list showing it available.

Will work on a fix.

OK I got side tracked by a different unrelated issue, so the full reproducer for this is:

A two node cluster.

On Node 1:

# Ensure no images in any projects first.
lxc image ls
<blank>

# Create project with image support.
lxc project create testproject -c features.profiles=false -c features.images=true -c features.storage.volumes=false

# Launch instance in testproject on node 1
lxc launch ubuntu:20.04 testcontainer1 --project testproject --target v1

# Confirm no images in default project yet.
lxc image ls --project default
<blank>

# Confirm image created in testproject.
lxc image ls --project testproject
<one image>

# Now try to launch an instance in the default project on node 2.
lxc launch ubuntu:20.04 testcontainer2  --project default --target v2
Error: Failed instance creation: Create instance from image: open /var/snap/lxd/common/lxd/images/f3658d5ae595ee1d33ad38c5dd25274ead8f8f26ff0797c1acbc4bb6a7862393: no such file or directory

# And, now image will existing in default project
lxc image ls --project default
<one image>

# However it is not copied to node2, and in the database is labelled as uncached.
lxd sql global 'select * from images'
+----+------------------------------------------------------------------+-----------------------------------------------+---------------+--------+--------------+----------------------+----------------------+--------------------------------+--------+--------------------------------+-------------+------------+------+
| id |                           fingerprint                            |                   filename                    |     size      | public | architecture |    creation_date     |     expiry_date      |          upload_date           | cached |         last_use_date          | auto_update | project_id | type |
+----+------------------------------------------------------------------+-----------------------------------------------+---------------+--------+--------------+----------------------+----------------------+--------------------------------+--------+--------------------------------+-------------+------------+------+
| 5  | f3658d5ae595ee1d33ad38c5dd25274ead8f8f26ff0797c1acbc4bb6a7862393 | ubuntu-20.04-server-cloudimg-amd64-lxd.tar.xz | 3.7241322e+08 | 0      | 2            | 2020-09-16T00:00:00Z | 2025-04-23T00:00:00Z | 2020-09-17T11:52:46.753350918Z | 1      | 2020-09-17T11:53:21.571741266Z | 1           | 2          | 0    |
| 6  | f3658d5ae595ee1d33ad38c5dd25274ead8f8f26ff0797c1acbc4bb6a7862393 | ubuntu-20.04-server-cloudimg-amd64-lxd.tar.xz | 3.7241322e+08 | 0      | 2            | 2020-09-16T00:00:00Z | 2025-04-23T00:00:00Z | 2020-09-17T11:53:21.420006252Z | 0      | 2020-09-17T11:53:21.571741266Z | 1           | 1          | 0    |
+----+------------------------------------------------------------------+-----------------------------------------------+---------------+--------+--------------+----------------------+----------------------+--------------------------------+--------+--------------------------------+-------------+------------+------+

My working fix for this is here: