How To Run Netbox IPAM in Docker Containers

Posted on 257 views

Welcome to this guide on how to run Netbox IPAM Tool in Docker Containers. But before we dive into the nub of this matter, let’s first get to know what the Netbox IPAM tool is all about.

Netbox is a free and open-source tool used to manage and document computer networks via the web. Netbox IPAM is written in Django. It helps ease the task of creating virtual implementations of devices in a data center which initially were being done on paper. The amazing features of Netbox IPAM include the following:

  • Vlan Management
  • VRF Management
  • IPAM – IP Address Management
  • DCIM – Data Center Infrastructure Management
  • Circuit Provider Management
  • Multi-Site (tenancy)
  • Single Converged Database
  • Rack Elevation
  • Report Alert
  • Connection Management – Interfaces/Console/Power
  • Customization Header For Logo’s etc

Running Netbox using Docker Containers is simple because, all the tedious task of installing dependencies such as Python, Django e.t.c is avoided.

Getting Started.

Before we begin on this guide, ensure that your system is up-to-date and the required packages installed.

## On Debian/Ubuntu
sudo apt update && sudo apt upgrade
sudo apt install curl vim git

## On RHEL/CentOS/RockyLinux 8
sudo yum -y update
sudo yum -y install curl vim git

## On Fedora
sudo dnf update
sudo dnf -y install curl vim git

1. Install Docker and Docker-Compose on Linux

This setup relies on Docker and docker-compose meeting the below requirements:

  1. Docker version 19.03 and above
  2. docker-compose version 1.28.0 and above

Install the latest version of Docker CE on Linux with the aid of the guide below.

Verify the installed version of Docker.

$ docker -v
Docker version 20.10.10, build b485636

Then add your system user to the docker group in order to execute docker commands without using the sudo command.

sudo usermod -aG docker $USER
newgrp docker

Now proceed and install Docker-compose on Linux. Download the latest version of docker-compose as below.

curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url  | grep docker-compose-linux-x86_64 | cut -d '"' -f 4 | wget -qi -

Make the file executable.

chmod +x docker-compose-linux-x86_64

Move the file to your PATH.

sudo mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose

Verify your installation by checking the docker-compose version.

$ docker-compose version
Docker Compose version v2.1.1

Now start and enable docker.

sudo systemctl start docker && sudo systemctl enable docker

2. Provision the Netbox IPAM server

All the components needed to build Netbox as a docker container are provided in the Github repository. Here, images are built and released to Docker Hub and Quay.io once a day.

Now git clone the Netbox docker file as below.

git clone -b release https://github.com/netbox-community/netbox-docker.git

Navigate into the Netbox directory.

cd netbox-docker

Modify the docker-compose.yml from the docker-compose.override.yml.example file as below.

tee docker-compose.override.yml <

Now we are set to start our docker container. But first, pull the required images for Netbox, PostgreSQL, Redis e.t.c

$ docker-compose pull

Several images will be pulled as below

...........
 ⠿ postgres Pulled                                                                                                                              13.5s
   ⠿ 9f97b97dbe44 Pull complete                                                                                                                  3.5s
   ⠿ 1b95022c44c5 Pull complete                                                                                                                  3.7s
   ⠿ 560a1e367f24 Pull complete                                                                                                                  8.0s
   ⠿ 41255ef20c58 Pull complete                                                                                                                  8.3s
   ⠿ 13107d5a09d7 Pull complete                                                                                                                  8.6s
   ⠿ 234db58e5916 Pull complete                                                                                                                  8.8s
   ⠿ 98ce0f30aef7 Pull complete                                                                                                                  9.1s
 ⠿ redis Pulled                                                                                                                                  9.3s
   ⠿ 97518928ae5f Already exists                                                                                                                 0.8s
   ⠿ 66f8c4150d27 Pull complete                                                                                                                  2.5s
 ⠿ redis-cache Pulled                                                                                                                            9.3s
   ⠿ 09a8bf17a0bf Pull complete                                                                                                                  3.1s
   ⠿ e547313af8e7 Pull complete                                                                                                                  4.0s
   ⠿ 335eeadfbde0 Pull complete                                                                                                                  4.6s
   ⠿ 7151fc2c01eb Pull complete    

Start the Netbox IPAM container.

$ docker-compose up

Sample Output:

[+] Running 10/10
 ⠿ Network netbox-docker_default                  Created                  0.2s
 ⠿ Volume "netbox-docker_netbox-media-files"      Created                  0.0s
 ⠿ Volume "netbox-docker_netbox-postgres-data"    Created                  0.0s
 ⠿ Volume "netbox-docker_netbox-redis-data"       Created                  0.0s
 ⠿ Container netbox-docker-redis-cache-1          Created                  0.7s
 ⠿ Container netbox-docker-postgres-1             Created                  0.6s
 ⠿ Container netbox-docker-redis-1                Created                  0.7s
 ⠿ Container netbox-docker-netbox-worker-1        Created                  0.5s
 ⠿ Container netbox-docker-netbox-housekeeping-1  Created                  0.5s
 ⠿ Container netbox-docker-netbox-1               Created                  0.3s
Attaching to netbox-docker-netbox-1, netbox-docker-netbox-housekeeping-1, netbox-docker-netbox-worker-1, netbox-docker-postgres-1, netbox-docker-redis-1, netbox-docker-redis-cache-1
....................

netbox-docker-netbox-1               | ⏳ Waiting for control socket to be created... (1/10)
netbox-docker-netbox-1               | 2021/11/15 10:37:29 [warn] 7#7 Unit is running unprivileged, then it cannot use arbitrary user and group.
netbox-docker-netbox-1               | 2021/11/15 10:37:29 [info] 7#7 unit started
netbox-docker-netbox-1               | 2021/11/15 10:37:29 [info] 20#20 discovery started
netbox-docker-netbox-1               | 2021/11/15 10:37:29 [notice] 20#20 module: python 3.9.5 "/usr/lib/unit/modules/python3.unit.so"
netbox-docker-netbox-1               | 2021/11/15 10:37:29 [info] 7#7 controller started
netbox-docker-netbox-1               | 2021/11/15 10:37:29 [notice] 7#7 process 20 exited with code 0
netbox-docker-netbox-1               | 2021/11/15 10:37:29 [info] 22#22 router started
netbox-docker-netbox-1               | 2021/11/15 10:37:29 [info] 22#22 OpenSSL 1.1.1l  24 Aug 2021, 101010cf
netbox-docker-netbox-1               | ⚙️ Applying configuration from /etc/unit/nginx-unit.json
netbox-docker-netbox-1               | 2021/11/15 10:37:30 [info] 26#26 "netbox" application started
netbox-docker-netbox-1               | ✅ Unit configuration loaded successfully
netbox-docker-netbox-1               | 2021/11/15 10:37:31 [notice] 7#7 process 18 exited with code 0

When you see the above output, the process has been completed, now exit, proceed and verify the containers are running:

$ docker ps
CONTAINER ID   IMAGE                               COMMAND                  CREATED          STATUS          PORTS                                       NAMES
ead31a95654a   netboxcommunity/netbox:v3.0-1.4.1   "/sbin/tini -- /opt/…"   2 minutes ago   Up 2 minutes   0.0.0.0:8000->8080/tcp, :::8000->8080/tcp   netbox-docker-netbox-1
d652988275e6   netboxcommunity/netbox:v3.0-1.4.1   "/sbin/tini -- /opt/…"   2 minutes ago   Up 2 minutes                                               netbox-docker-netbox-housekeeping-1
6ee0e21ecde0   netboxcommunity/netbox:v3.0-1.4.1   "/sbin/tini -- /opt/…"   2 minutes ago   Up 2 minutes                                               netbox-docker-netbox-worker-1
3ff7e0c6b174   redis:6-alpine                      "docker-entrypoint.s…"   2 minutes ago   Up 2 minutes   6379/tcp                                    netbox-docker-redis-cache-1
92e49f207764   redis:6-alpine                      "docker-entrypoint.s…"   2 minutes ago   Up 2 minutes   6379/tcp                                    netbox-docker-redis-1
77908ccce0ca   postgres:13-alpine                  "docker-entrypoint.s…"   2 minutes ago   Up 2 minutes   5432/tcp                                    netbox-docker-postgres-1

If you have a firewall enabled, allow port 8000 as below.

##For Firewalld
sudo firewall-cmd --zone=public --add-port=8000/tcp --permanent
sudo firewall-cmd --reload

##For UFW
sudo ufw allow 8000/tcp

3. Access the Netbox IPAM tool Web UI

Everything is set, we can now proceed and access the Netbox IPAM web UI with the URL http://Hostname:8000 or http://IP_Address:8000.

How-To-Run-Netbox-IPAM-Tool-in-Docker-Containers-6-1-1024x515

Log in to the page with the default credentials as Username: admin, Password: admin, and API Token: 0123456789abcdef0123456789abcdef01234567

How-To-Run-Netbox-IPAM-Tool-in-Docker-Containers

On successful login, you will see this page.

How-To-Run-Netbox-IPAM-Tool-in-Docker-Containers-1-1-1024x472

Now here, you can navigate using the panel on your left as shown.

How-To-Run-Netbox-IPAM-Tool-in-Docker-Containers-2

While on this panel, you can add the devices, connections, circuits, IPAM, clusters, power supply, and many other items to be managed.

This gives an implementation that with Netbox IPAM tool, it is so easy to manage a data center by adding the required devices.

To add a device let’s say a router, you will add the information below.

How-To-Run-Netbox-IPAM-Tool-in-Docker-Containers-3

In case you want to stop all the running containers, run the below command:

$ docker-compose stop

You can remove the containers as below.

$ docker-compose stop && docker-compose rm

Sample Output:

+] Running 6/0
 ⠿ Container netbox-docker-netbox-housekeeping-1  Stopped                  0.0s
 ⠿ Container netbox-docker-netbox-1               Stopped                  0.0s
 ⠿ Container netbox-docker-netbox-worker-1        Stopped                  0.0s
 ⠿ Container netbox-docker-redis-cache-1          Stopped                  0.0s
 ⠿ Container netbox-docker-redis-1                Stopped                  0.0s
 ⠿ Container netbox-docker-postgres-1             Stopped                  0.0s
? Going to remove netbox-docker-netbox-1, netbox-docker-netbox-housekeeping-1, netbox-docker-netbox-worker-1, netbox-docker-redis-cache-1, netbox-docker-redis-1, netbox-docker-postgres-1 (y/N) y

Conclusion

That is it! At this point, we can all agree that running Netbox IPAM Tool in Docker Containers is easier. I hope you succeeded to set up the Netbox IPAM tool Docker container.

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.