Netbox Plugin customize image

Hello all,

I am trying to create a customize docker image with plugins for Metbox. There are several documentations. At least I am following
Using Netbox Plugins · netbox-community/netbox-docker Wiki

What I get typing “docker compose build --no-cache” is:

root@net-netboxtest:/opt/netbox/netbox-docker# docker compose build --no-cache
[+] Building 0.5s (8/12)
=> [internal] load local bake definitions                                                                                                              0.0s
=> => reading from stdin 547B                                                                                                                          0.0s
=> [internal] load build definition from Dockerfile-Plugins                                                                                            0.0s
=> => transferring dockerfile: 1.18kB                                                                                                                  0.0s
=> [internal] load metadata for docker.io/netboxcommunity/netbox:latest                                                                                0.0s
=> [internal] load .dockerignore                                                                                                                       0.0s
=> => transferring context: 234B                                                                                                                       0.0s
=> CACHED [1/7] FROM docker.io/netboxcommunity/netbox:latest                                                                                           0.0s
=> [internal] load build context                                                                                                                       0.0s
=> => transferring context: 172B                                                                                                                       0.0s
=> [2/7] COPY ./plugin_requirements.txt /opt/netbox/                                                                                                   0.1s
=> ERROR [3/7] RUN /root/.local/bin/uv pip install -r /opt/netbox/plugin_requirements.txt                                                              0.3s
------
> [3/7] RUN /root/.local/bin/uv pip install -r /opt/netbox/plugin_requirements.txt:
0.243 /bin/sh: 1: /root/.local/bin/uv: not found
------
[+] build 0/1
⠙ Image netbox:latest-plugins Building                                                                                                                  0.6s
Dockerfile-Plugins:11

--------------------

  9 |     #COPY /opt/netbox/netbox-docker/plugin_requirements.txt /opt/netbox/

 10 |

 11 | >>> RUN /root/.local/bin/uv pip install -r /opt/netbox/plugin_requirements.txt

 12 |

 13 |

--------------------

failed to solve: process "/bin/sh -c /root/.local/bin/uv pip install -r /opt/netbox/plugin_requirements.txt" did not complete successfully: exit code: 127

root@muesrv01-nbtest:/opt/netbox/netbox-docker# ls /opt/netbox/
devicetype-library  netbox-docker
root@muesrv01-nbtest:/opt/netbox/netbox-docker# => CACHED [1/7] FROM docker.io/netboxcommunity/netbox:latest                                                                                           0.0s
=> [internal] load build context                                                                                                                       0.0s
=> => transferring context: 172B                                                                                                                       0.0s
=> [2/7] COPY ./plugin_requirements.txt /opt/netbox/                                                                                                   0.1s
=> ERROR [3/7] RUN /root/.local/bin/uv pip install -r /opt/netbox/plugin_requirements.txt                                                              0.3s
------
> [3/7] RUN /root/.local/bin/uv pip install -r /opt/netbox/plugin_requirements.txt:
0.243 /bin/sh: 1: /root/.local/bin/uv: not found
------
[+] build 0/1
⠙ Image netbox:latest-plugins Building                                                                                                                  0.6s
Dockerfile-Plugins:11

--------------------

9 |     #COPY /opt/netbox/netbox-docker/plugin_requirements.txt /opt/netbox/

10 |

11 | >>> RUN /root/.local/bin/uv pip install -r /opt/netbox/plugin_requirements.txt

12 |

13 |

--------------------

failed to solve: process "/bin/sh -c /root/.local/bin/uv pip install -r /opt/netbox/plugin_requirements.txt" did not complete successfully: exit code: 127

What I see is that the line

[2/7] COPY ./plugin_requirements.txt /opt/netbox/

does not copy the .txt file to its locatin. Coping the file on the console with cp works. So the syyntax should be fine. Also the command producing the following error is fine

=> ERROR [3/7] RUN /root/.local/bin/uv pip install -r /opt/netbox/plugin_requirements.txt

uv can be found in that directory. Also copying the .txt file to that location before running docker compose does not change something.

Any hint to solve would be cool
Thanks

Without seeing your Dockerfile, we can only assume how /root/.local/bin/uv is made available in the image. Either it must exist in the base image you use, or you install it within your Dockerfile, or you copy it from a file within you build context into a container (which is not recommended!).

Note: A build can not access files outside the build context.

I think that is the answer. The docker file looks like

FROM netboxcommunity/netbox:latest

# Switch to root to install packages and create directories 
USER root

COPY ./plugin_requirements.txt /opt/netbox/
RUN /usr/local/bin/uv pip install -r /opt/netbox/plugin_requirements.txt

# Create required directory for Topology Views images 
RUN mkdir -p /opt/netbox/netbox/static/netbox_topology_views/img && 
 chown -R unit:root /opt/netbox/netbox/static/netbox_topology_views 

# These lines are only required if your plugin has its own static files.
COPY configuration/configuration.py /etc/netbox/config/configuration.py
COPY configuration/plugins.py /etc/netbox/config/plugins.py

# RUN DEBUG="true" SECRET_KEY="dummydummydummydummydummydummydummydummydummydummy" /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py collectstatic --no-input
# Collect static files 
# SECRET_KEY must be 50+ characters! 
RUN SECRET_KEY="dummyKeyWithMinimumLength-------------------------" /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py collectstatic --no-input

# Switch back to unit user 
USER unittype or paste code here

I didn’t made uv available. That wasn’t mentioned in the documentation…

I am glad it’s sorted out now.

Some observations:

The Dockerfile you shared is not the same that created the output you shared in your first post.

It uses a different path for the uv binary. The shared Dockerfile uses the correct path, which btw. matches the path shown in the example in the wiki.

The first USER instruction is not required, as the base image already uses the root user. Though, the explicit USER instruction might prevent breakage in the future, in case it should change in the base image at one point.

The user unit does not exist in the image .

Looks like something that doesn’t belong into the image, but should be rather configured when creating a container based on the image.

Again: no unit or unittype user available in the image.

There was an old image bound to docker. After removing it I don’t see this error anymore. The image was more than a year ago. Ihad forgotten that it exists.