Incus OCI Database Container connections

@stgraber I have been working on understanding how to achieve a connection to a mongodb database container.

In a docker-compose file, it is typical to have directives such as:

    links:
      - mongo
    depends_on:
      - mongo
    restart: unless-stopped

The “links” directive provides a way to associate the application with the database container. The depends_on directive waits for the database container to be available before the application starts and the restart policy is something I have heard is in the works for Incus OCI containers.

So, in incus I create the database thusly:

incus create docker:mongo c1-db
mkdir ./c1-data
incus config device add c1-db mongodb disk source=/home/scott/c1-data path=/data/db shift=true

The application would be:

incus create docker:myapp:latest c1 -c environment.MONGODB_URL=mongodb://c1-db:27017/mydatabase
incus config device add c1 hostport3000 proxy connect="tcp:127.0.0.1:3000" listen="tcp:0.0.0.0:3000"

The user would then be able to access the app at port 3000 on the address of the incus server.

A docker-compose for this application works perfectly.

Unfortunately, as a pair of incus OCI containers, the c1 application fails to start because it is not connecting to the c1-db database. This may be some odd mongodb issue, but it is equally possible that something else is going wrong.

Ideas?

Unlike docker containers, Incus containers are system containers and are not meant to be ephemeral and short-lived by default.

That would remove the necessity of mounting an host directory for each container. Ideally the storage pools should be utilised unless warranted.

For docker compose, links is simply a way to have a virtual network connection between multiple containers. Incus does that already and every container is accessible via <container-name> or <container-name>.incus.

As for the restart policy, running containers already do startup automatically on server restart.

The only bit that AFAIK there is no direct alternative yet in Incus is depends_on. While it makes sense for application containers, it is not as relevant for system containers.

The workaround for that is to have a logic (or script) in the application that delays startup until the database is ready.

You should be using c1-db.incus:27017 so it can actually resolve to the IP address of c1-db.

Not entirely true. Incus “OCI” containers run docker apps and the same rules apply in terms of run and exit or “endure” like a web browser. Mounting a host folder is logically equivalent to “docker volumes” and without reference to a volume or host folder, no persistent data is preserved when the incus OCI container exits. That’s exactly like with a “docker run”.

My question is specifically on why I cannot achieve a database connection with mongodb given that I am using <container-name.incus> as you will note from my example. I know how the product works today. I am pointing out where I found specific issues and was documenting them. I did have success in doing the same thing with mariadb. I am not sure that the environment variable passing is working properly in the mongodb example I provided.