Upgrading Docker-based Netbox (IPAM) while preserving stored data

Tested to upgrade from v. 0.19 to v. 0.23

At the time of writing this, the Docker containers of Netbox are not being provided by the vendor, rather a “community” project.

There are 6 containers in total that work together to provide the IPAM service:

  • netbox
  • netbox-worker
  • nginx
  • postgres (sql)
  • redis
  • redis-cache

All the IPAM data is stored inside the postgres container; hence, it’s important to backup that data before proceeding with any update.

Step #1

Get postgres container id

docker ps

Back-up IPAM data

docker exec -t POSTGRES_CONTAINER_ID pg_dumpall -c -U netbox > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql

Now protect this scared dump file

Step #2

Go to /opt/netbox-docker/

Stop netbox-docker

docker-compose down

Step #3

Rename docker-composer.yml and configuration/ldap_config.py 

Renaming will preserve the config in those files from being overwritten. Also, you won’t be able to progress to the next steps with those files have a different baseline from the public git repository

Step #4

Pull the latest netbox from the git repository

git pull origin release

docker-compose rm -fs netbox netbox-worker postgres

docker-compose pull

Step #5

Clean up old data

docker volume rm netbox-docker_netbox-postgres-data

docker volume rm netbox-docker_netbox-static-files

Step #6

Restore postgres database content

docker-compose up postgres

cat your_dump.sql | docker exec -i POSTGRES_CONTAINER_ID psql -U netbox

Step #7

Finally, bring everything up again

docker-compose up -d