# How to add multiple containers in mender layer

**URL:** <https://hub.mender.io/t/how-to-add-multiple-containers-in-mender-layer/6050>\
**Category:** Yocto Project\
**Tags:** yocto, nxp, docker, kirkstone\
**Created:** [July 31, 2023, 11:56am UTC](https://hub.mender.io/t/how-to-add-multiple-containers-in-mender-layer/6050 "2023-07-31T11:56:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aysha](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@Aysha](https://hub.mender.io/u/Aysha)\
**Post date:** [July 31, 2023, 11:56am UTC](https://hub.mender.io/t/how-to-add-multiple-containers-in-mender-layer/6050/1 "2023-07-31T11:56:51Z")

</div>

Hi Team,

As per the article, [How to update a Docker container with Mender using Raspberry Pi | Mender](https://mender.io/blog/how-to-update-a-docker-container-with-mender-using-raspberry-pi) the docker is used to update modules. In this scenario, whether only one container is used or multiple containers are used? If so, how it can be done. Please provide procedure if any.

How to perform this updation with multiple containers using Yocto (iMx6 setup)? Please provide procedure if any.

Thanking you  
Best regards,  
Aysha

---

<div class="post-metadata">

**Author:** ![TheYoctoJester](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/theyoctojester/32/1444_2.png) [@TheYoctoJester](https://hub.mender.io/u/TheYoctoJester)\
**Post date:** [July 31, 2023, 1:07pm UTC](https://hub.mender.io/t/how-to-add-multiple-containers-in-mender-layer/6050/2 "2023-07-31T13:07:03Z")

</div>

Hello @Aysha,

The tutorial for using the Docker update module is [here](https://hub.mender.io/t/docker/324). You can use it for one or more container images to be managed.

Greetz,  
Josef

---

<div class="post-metadata">

**Author:** ![Aysha](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@Aysha](https://hub.mender.io/u/Aysha)\
**Post date:** [August 1, 2023, 6:44am UTC](https://hub.mender.io/t/how-to-add-multiple-containers-in-mender-layer/6050/3 "2023-08-01T06:44:38Z")

</div>

Hi Josef,  
Thanks for your response.  
The link shared is of Ubuntu, can I know how to perform in **Yocto**? What changes to be made? In meta-mender layer, which file to be used to add custom container information?

Regards,  
Aysha

---

<div class="post-metadata">

**Author:** ![TheYoctoJester](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/theyoctojester/32/1444_2.png) [@TheYoctoJester](https://hub.mender.io/u/TheYoctoJester)\
**Post date:** [August 1, 2023, 9:45am UTC](https://hub.mender.io/t/how-to-add-multiple-containers-in-mender-layer/6050/4 "2023-08-01T09:45:18Z")

</div>

Hello @Aysha,

EDIT: correction.

Unless you have modified the metadata for the Mender Client in your layers, the `docker` Update Module is installed by default: [https://github.com/mendersoftware/meta-mender/blob/c0f539ffedba6070963abe64c67c4c5d8b1ec872/meta-mender-core/recipes-mender/mender-client/mender-client.inc#L48](https://github.com/mendersoftware/meta-mender/blob/c0f539ffedba6070963abe64c67c4c5d8b1ec872/meta-mender-core/recipes-mender/mender-client/mender-client.inc#L48)

Greetz,  
Josef

---

<div class="post-metadata">

**Author:** ![Aysha](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@Aysha](https://hub.mender.io/u/Aysha)\
**Post date:** [August 4, 2023, 10:05am UTC](https://hub.mender.io/t/how-to-add-multiple-containers-in-mender-layer/6050/5 "2023-08-04T10:05:01Z")

</div>

Dear Team,

As I was trying to update the container image in i.MX device using mender. I had created artifact file using below command.  
./mender-artifact write rootfs-image -t imx -n container -f container.tar.gz -o artifact.mender

But while deployment process, I am unable to deploy with below failure messages.

2023-08-04 09:48:06 +0000 UTC info: Running Mender client version: 3.5.0  
2023-08-04 09:48:08 +0000 UTC info: State transition: update-fetch [Download\_Enter] → update-store [Download\_Enter]  
2023-08-04 09:48:08 +0000 UTC info: No public key was provided for authenticating the artifact  
2023-08-04 09:48:11 +0000 UTC info: Opening device “/dev/mmcblk1p2” for writing  
2023-08-04 09:48:11 +0000 UTC info: Native sector size of block device /dev/mmcblk1p2 is 512 bytes. Mender will write in chunks of 1048576 bytes  
2023-08-04 09:51:18 +0000 UTC info: All bytes were successfully written to the new partition  
2023-08-04 09:51:18 +0000 UTC info: The optimized block-device writer wrote a total of 308 frames, where 0 frames did need to be rewritten (i.e., skipped)  
2023-08-04 09:51:18 +0000 UTC info: Wrote 322796469/322796469 bytes to the inactive partition  
2023-08-04 09:51:19 +0000 UTC info: State transition: update-store [Download\_Enter] → update-after-store [Download\_Leave]  
2023-08-04 09:51:19 +0000 UTC info: State transition: update-after-store [Download\_Leave] → mender-update-control-refresh-maps [none]  
2023-08-04 09:51:19 +0000 UTC info: State transition: mender-update-control-refresh-maps [none] → mender-update-control [none]  
2023-08-04 09:51:19 +0000 UTC info: State transition: mender-update-control [none] → update-install [ArtifactInstall]  
2023-08-04 09:51:19 +0000 UTC info: Enabling partition with new image installed to be a boot candidate: 2  
2023-08-04 09:51:20 +0000 UTC info: State transition: update-install [ArtifactInstall] → mender-update-control-refresh-maps [none]  
2023-08-04 09:51:20 +0000 UTC info: State transition: mender-update-control-refresh-maps [none] → mender-update-control [none]  
2023-08-04 09:51:20 +0000 UTC info: State transition: mender-update-control [none] → reboot [ArtifactReboot\_Enter]  
2023-08-04 09:51:21 +0000 UTC info: Rebooting device(s)  
2023-08-04 09:51:21 +0000 UTC info: Mender rebooting from active partition: /dev/mmcblk1p1  
2023-08-04 09:51:21 +0000 UTC error: error forwarding from client to backend: websocket: close 1006 (abnormal closure): unexpected EOF  
2023-08-04 09:51:22 +0000 UTC warning: error while sending close message: write tcp 127.0.0.1:44645-\>127.0.0.1:52362: use of closed network connection  
2023-08-04 09:51:23 +0000 UTC info: Daemon terminated with SIGTERM  
2023-08-04 09:54:22 +0000 UTC info: Running Mender client version: 3.5.0  
2023-08-04 09:54:22 +0000 UTC info: State transition: init [none] → after-reboot [ArtifactReboot\_Leave]  
2023-08-04 09:54:22 +0000 UTC error: transient error: Reboot to the new update failed. Expected “upgrade\_available” flag to be true but it was false. Either the switch to the new partition was unsuccessful, or the bootloader rolled back  
2023-08-04 09:54:22 +0000 UTC info: State transition: after-reboot [ArtifactReboot\_Leave] → rollback [ArtifactRollback]  
2023-08-04 09:54:22 +0000 UTC info: Performing rollback  
2023-08-04 09:54:22 +0000 UTC info: No update available, so no rollback needed.  
2023-08-04 09:54:22 +0000 UTC info: State transition: rollback [ArtifactRollback] → rollback-reboot [ArtifactRollbackReboot\_Enter]  
2023-08-04 09:54:22 +0000 UTC info: Rebooting device(s) after rollback  
2023-08-04 09:54:22 +0000 UTC info: Mender rebooting from inactive partition: /dev/mmcblk1p1  
2023-08-04 09:54:24 +0000 UTC info: Daemon terminated with SIGTERM  
2023-08-04 09:57:19 +0000 UTC info: Running Mender client version: 3.5.0  
2023-08-04 09:57:19 +0000 UTC info: Mender shut down in state: rollback-reboot  
2023-08-04 09:57:19 +0000 UTC info: State transition: init [none] → verify-rollback-reboot [ArtifactRollbackReboot\_Leave]  
2023-08-04 09:57:19 +0000 UTC info: State transition: verify-rollback-reboot [ArtifactRollbackReboot\_Leave] → after-rollback-reboot [ArtifactRollbackReboot\_Leave]  
2023-08-04 09:57:19 +0000 UTC info: State transition: after-rollback-reboot [ArtifactRollbackReboot\_Leave] → update-error [ArtifactFailure]  
2023-08-04 09:57:19 +0000 UTC info: State transition: update-error [ArtifactFailure] → cleanup [Error]  
2023-08-04 09:57:19 +0000 UTC info: State transition: cleanup [Error] → update-status-report [none]  
2023-08-04 09:57:19 +0000 UTC info: Device unauthorized; attempting reauthorization  
2023-08-04 09:57:19 +0000 UTC info: Output (stderr) from command “/usr/share/mender/identity/mender-device-identity”: using interface /usr/share/  
2023-08-04 09:57:21 +0000 UTC info: successfully received new authorization data from server [https://hosted.mender.io](https://hosted.mender.io)  
2023-08-04 09:57:21 +0000 UTC info: Local proxy started  
2023-08-04 09:57:21 +0000 UTC info: Reauthorization successful

Please let me know what changes to be made to deploy container successfully to i.Mx device.

Best regards,  
Ayshathul Thuhara

---

<div class="post-metadata">

**Author:** ![TheYoctoJester](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/theyoctojester/32/1444_2.png) [@TheYoctoJester](https://hub.mender.io/u/TheYoctoJester)\
**Post date:** [August 4, 2023, 1:39pm UTC](https://hub.mender.io/t/how-to-add-multiple-containers-in-mender-layer/6050/6 "2023-08-04T13:39:12Z")

</div>

Hi @Aysha,

without exactly knowing what you put into the Artifact, the only guess I can take is based on this line in the log

```auto
2023-08-04 09:54:22 +0000 UTC error: transient error: Reboot to the new update failed. Expected “upgrade_available” flag to be true but it was false. Either the switch to the new partition was unsuccessful, or the bootloader rolled back

```

So it seems that whatever is in that `container.tar.gz` that you tried to install is not properly handled. Even more guessing: it is not a full root filesystem, as you are talking about containers.

```auto
mender-artifact write rootfs-image

```

is meant for full system deployments. To create an Artifact for the `docker` Update Module, use the matching [generator script](https://github.com/mendersoftware/mender/blob/master/support/modules-artifact-gen/docker-artifact-gen), as mentioned in the already linked [tutorial](https://hub.mender.io/t/docker/324).

Greetz,  
Josef

---

<div class="post-metadata">

**Author:** ![Aysha](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@Aysha](https://hub.mender.io/u/Aysha)\
**Post date:** [August 7, 2023, 4:46am UTC](https://hub.mender.io/t/how-to-add-multiple-containers-in-mender-layer/6050/7 "2023-08-07T04:46:03Z")

</div>

Hi @TheYoctoJester ,  
Thanks for your response.  
As I wanted to update a custom image using docker, the custom-image (docker-container.tar) contains a custom application.  
I used below command to generate it,

> $ mender-artifact write rootfs-image -t imx -n release-2.5 --software-version rootfs-v1 -f docker-container.tar -o artifact.mender  
> Writing Artifact…  
> Version ✓  
> Manifest ✓  
> Manifest signature ✓  
> Header ✓  
> Payload  
> … - 100 %

I had even tried to generate artifact.mender using docker-artifact-gen, which resulted in below error.

> $docker-artifact-gen -n container-update-1.0 -t imx -o /home/root/ docker-container.tar  
> Using default tag: latest  
> Error response from daemon: pull access denied for docker-container.tar, repository does not exist or may require ‘docker login’: denied: requested access to the resource is denied

Please let me know how to generate artifact.mender for a docker custom image. Since I am new to mender.

Best regards,  
Aysha

---

<div class="post-metadata">

**Author:** ![TheYoctoJester](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/theyoctojester/32/1444_2.png) [@TheYoctoJester](https://hub.mender.io/u/TheYoctoJester)\
**Post date:** [August 7, 2023, 5:49am UTC](https://hub.mender.io/t/how-to-add-multiple-containers-in-mender-layer/6050/8 "2023-08-07T05:49:24Z")

</div>

Hi @Aysha ,

I think you are randomly mixing up things, and therefore they do not work. By custom image, we understand a full linux root filesystem including your modifications. So, the command style `mender-artifact write rootfs-image` only applies if you have this. The filename `docker-container.tar` sounds very different. So, it does not apply here!

The `docker-artifact-gen` script is suitable for packing docker containers into a Mender artifact. Please use it, and please, read the tutorial. It expects the name (and optionally tag) of the container, not an archive. The [corresponding section](https://hub.mender.io/t/docker/324#artifact-creation-8) explains the required arguments in detail.

Greetz,  
Josef

---

<div class="post-metadata">

**Author:** ![Aysha](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@Aysha](https://hub.mender.io/u/Aysha)\
**Post date:** [August 7, 2023, 12:37pm UTC](https://hub.mender.io/t/how-to-add-multiple-containers-in-mender-layer/6050/9 "2023-08-07T12:37:31Z")

</div>

Hi @TheYoctoJester,

Sorry for the confusion, right now I am in state to update a single docker container image. For that I was using below command, which resulted in update failure.

> mender-artifact write rootfs-image -t imx -n release-2.5 --software-version rootfs-v1 -f docker-container.tar -o artifact.mender

By considering your suggestions, I will try to use docker-artifact-gen. I have seen in docker-artifact-gen uses mender-artifact to generate the .mender file,

> mender-artifact write module-image -t imx6 -o docker-2.mender -T docker -n docker-2.0 -f docker-container.tar

Here docker-container.tar is my custom container image, which should get update during updation.  
After performing this, I am able to update the image over the target device with few static changes in /usr/share/mender/modules/v3/docker.

> ```
> ArtifactInstall)
> 
> ```

```
    cp "$FILES"/files/* /home/root/
    docker load -i /home/root/docker-container.tar
    docker stop hello-world || true
    docker rm hello-world || true
    docker run -d --name hello-world hello-world-image:latest

    ;;

```

But I found there are few containers were not listed in /var/lib/mender/modules/v3/payloads/0000/tree/tmp/prev\_containers.list file, even though they were listed in “docker container list -a”.

> :# ls /var/lib/mender/modules/v3/payloads/0000/  
> :#

Can I know how this prev\_containers.list file is created and is there any changes to be made to get containers listed in prev\_container.list.

Thanking you,  
Regards,  
Aysha

---

<div class="post-metadata">

**Author:** ![Aysha](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@Aysha](https://hub.mender.io/u/Aysha)\
**Post date:** [August 8, 2023, 9:19am UTC](https://hub.mender.io/t/how-to-add-multiple-containers-in-mender-layer/6050/10 "2023-08-08T09:19:44Z")

</div>

Hi Team,

As I had tried to generate mender.artifact using docker-artifact-gen. I had observed that the docker images should be available in docker repo. And in my case I wanted to have the docker container in tar format, which contains compressed docker image.

I had even tried one of the image to upload to target device from mender. But the docker update was not shown success even mender shown as success. While checking on this, I found /var/lib/mender/modules/v3/payloads/0000/tree/tmp/prev\_containers.list empty and not available.  
This file wasa read by docker script i.e., /usr/share/mender/modules/v3/docker.

Can I know which script creates this file “/var/lib/mender/modules/v3/payloads/0000/tree/tmp/prev\_containers.list”, and when this file is created and updated.

Hoping for your reply  
Regards,  
Aysha

---

<div class="post-metadata">

**Author:** ![TheYoctoJester](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/theyoctojester/32/1444_2.png) [@TheYoctoJester](https://hub.mender.io/u/TheYoctoJester)\
**Post date:** [August 9, 2023, 7:41am UTC](https://hub.mender.io/t/how-to-add-multiple-containers-in-mender-layer/6050/11 "2023-08-09T07:41:17Z")

</div>

Hi @Aysha,

Okay, so you are effectively asking for “how can I update multiple containers on a device, and have them transported in the Artifact”.  
This is not a use case that we have a ready to run solution, you need to create a custom Update Module. Please find the documentation [here](https://docs.mender.io/artifact-creation/create-a-custom-update-module), and inspiration in the [Update Module repository](https://github.com/mendersoftware/mender-update-modules).

The snippet that you listed is part of the File API that Update Modules can use, as documented [here](https://github.com/mendersoftware/mender/blob/master/Documentation/update-modules-v3-file-api.md#file-api)

Greetz,  
Josef
