Skip to content

Instantly share code, notes, and snippets.

@jessedufrene
Last active April 25, 2024 21:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jessedufrene/0eba7d6982742c2ffcf99e136af1b587 to your computer and use it in GitHub Desktop.
Save jessedufrene/0eba7d6982742c2ffcf99e136af1b587 to your computer and use it in GitHub Desktop.
Netbox docker compose
# username for login is 'admin'
SUPERUSER_EMAIL=admin@netbox.local
SUPERUSER_PASSWORD=
DB_PASSWORD=
REDIS_PASSWORD=

Netbox Docker Compose

A straigntforward docker compose setup for Netbox that, unlike what Netbox officially provides, allows simple updating, simple configuration, no git clone needed, and local mounts instead of volumes. Also has an optional nginx setup to give Netbox its own IP on your network at port 80, as well as optional support for adding plugins via a simple Dockerfile.

Setup

  1. Use a password generator to add some passwords to the .env file
  2. Optionally change the email in the .env file
  3. Check the docker-compose.yml and:
    1. Check the netbox service has the port you want, or remove it if you don't want that.
    2. Check the nginx service to be sure it has the IP you want, or remove everything below the comment if you don't want that. Also ensure it has the correct bridge network name.
  4. Run docker compose up -d ; docker compose logs -f to pull the images, start the services, and watch the logs.
  5. Watch for any errors, and press Ctrl+C when you're done with the log.

Add plugins

  1. In docker-compose.yml, comment out the image line for the netbox service, and uncomment the build lines.
  2. Follow any instructions the plugins have for setting them up.
    • pip install commands should be added to netbox.Dockerfile
    • edits to configuration.py should be done in netbox/configuration.py
  3. Run docker compose build --pull to build the image.
  4. Continue at step 4 of the Setup instructions.

Updates

  1. If using plugins, run docker compose build --pull
  2. Run docker compose pull then docker compose up -d
  3. (optional) clean up after with docker image prune -af

If you see something in the logs about the Postgres version, try changing postgres:latest to be something like postgres:14

License

This is released under the Unlicense license. See LICENSE for details.

---
version: "2.1"
services:
netbox:
image: lscr.io/linuxserver/netbox:latest
# build:
# context: .
# dockerfile: netbox.Dockerfile
restart: unless-stopped
container_name: netbox
environment:
- PUID=1000
- PGID=1000
- TZ=America/Denver
- SUPERUSER_EMAIL=${SUPERUSER_EMAIL}
- SUPERUSER_PASSWORD=${SUPERUSER_PASSWORD}
- ALLOWED_HOST=*
- DB_NAME=netbox
- DB_USER=netbox
- DB_PASSWORD=${DB_PASSWORD}
- DB_HOST=postgres
- DB_PORT=5432
- REDIS_HOST=redis
- REDIS_PORT=6379
- REDIS_PASSWORD=${REDIS_PASSWORD}
- REDIS_DB_TASK=0
- REDIS_DB_CACHE=1
volumes:
- ./netbox:/config
ports:
- 8000:8000
postgres:
image: postgres:latest
restart: unless-stopped
environment:
- POSTGRES_USER=netbox
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=netbox
volumes:
- ./postgres:/var/lib/postgresql/data
redis:
image: redis:latest
restart: unless-stopped
command:
- sh
- -c
- redis-server --requirepass $$REDIS_PASSWORD
environment:
- REDIS_PASSWORD=${REDIS_PASSWORD}
volumes:
- ./redis:/data
# everything below is optional, it allows for Netbox to be at a different IP from the default
nginx:
image: nginx:latest
restart: unless-stopped
networks:
br0:
ipv4_address: 192.168.1.64
default:
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
networks:
default:
br0:
external: true
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>
FROM linuxserver/netbox:latest
RUN pip install netbox-plugin-1 netbox-plugin-2 netbox-plugin-3
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name _; # Listen on all hostnames
client_max_body_size 8M; # allow uploads up to 8MB
location / {
proxy_pass http://netbox:8000; # Redirect traffic to your_service
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment