Switching back to root user in docker build causes errors

I have a base docker image that is built off of python clearlinux and that base image sets up the user we want our application to run under:

FROM clearlinux/python:3.7.5
...
RUN groupadd runuser && useradd --shell /bin/bash runuser -g runuser
USER runuser 
...

Then one of our applications builds off that same image and needs to install nginx as a supporting service:

FROM ...image that was built above...
USER 0
RUN swupd bundle-add nginx

This causes an error:

#12 1.225 No extra files need to be downloaded
#12 1.225  [100%]
#12 1.226 Installing files...
#12 1.226  [  1%]
#12 1.226  [  3%]
#12 1.226  [  5%]
#12 1.227  [  7%]
#12 1.229 Failed to install 1 of 1 bundles
#12 1.229 Error: File staging failed: /usr/lib64/nginx
#12 1.229 Error: Failed to install required files [100%]
#12 ERROR: executor failed running [/bin/sh -c swupd bundle-add nginx]: exit code: 6

This only seems to be a problem when the build system switches between users and back to root for the addition of nginx. If nginx is installed before switching users in the base build, no issues. But we don’t want nginx in the base build.

Any suggestions on how to correctly switch back to the root user to add a package?

Thanks!

I solved this issue by adding:

RUN swupd clean

Before the second bundle-add