We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – How To Run Netbox IPAM in Docker Containers

Learn how to – How To Run Netbox IPAM in Docker Containers.

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.

Step 1: Update system and install deps

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 -y
[ -f /var/run/reboot-required ] && sudo reboot -f
sudo apt install curl vim git -y

## 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

Step 2: Install Docker and Docker-Compose

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.17.2

Now start and enable docker.

sudo systemctl start docker && sudo systemctl enable docker

Step 3: 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 <<EOF
version: '3.4'
services:
  netbox:
    ports:
      - 8000:8080
EOF

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 compose ps
NAME                          IMAGE                                         COMMAND                  SERVICE             CREATED             STATUS                   PORTS
netbox-docker-netbox-1        docker.io/netboxcommunity/netbox:v3.4-2.5.2   "/usr/bin/tini -- /o…"   netbox              4 minutes ago       Up 4 minutes (healthy)   0.0.0.0:8000->8080/tcp, :::8000->8080/tcp
netbox-docker-postgres-1      docker.io/postgres:15-alpine                  "docker-entrypoint.s…"   postgres            4 minutes ago       Up 4 minutes             5432/tcp
netbox-docker-redis-1         docker.io/redis:7-alpine                      "docker-entrypoint.s…"   redis               4 minutes ago       Up 4 minutes             6379/tcp
netbox-docker-redis-cache-1   docker.io/redis:7-alpine                      "docker-entrypoint.s…"   redis-cache         4 minutes ago       Up 4 minutes             6379/tcp

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

Step 4: 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.

Log in to the page, you need to create your admin user. This can be done using the command:

docker compose exec netbox /opt/netbox/netbox/manage.py createsuperuser

Sample Output:

Now use the created user to access the dashboard.

On successful login, you will see this page.

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

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.

You can also create API tokens with an expiry date, allowed IPs and networks to authenticate to Netbox. The API tokens can be created as shown:

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

$ docker compose stop
[+] Running 6/6
 ✔ Container netbox-docker-netbox-housekeeping-1  Stopped                                                                                                                 0.0s
 ✔ Container netbox-docker-netbox-worker-1        Stopped                                                                                                                 0.0s
 ✔ Container netbox-docker-netbox-1               Stopped                                                                                                                 1.2s
 ✔ Container netbox-docker-redis-cache-1          Stopped                                                                                                                 0.3s
 ✔ Container netbox-docker-postgres-1             Stopped                                                                                                                 0.4s
 ✔ Container netbox-docker-redis-1                Stopped                                                                                                                 0.3s

You can remove the containers as below.

$ docker compose stop && docker compose rm

Sample Output:

[+] Running 6/0
 ✔ Container netbox-docker-netbox-worker-1        Stopped                                                                                                                 0.0s
 ✔ Container netbox-docker-netbox-housekeeping-1  Stopped                                                                                                                 0.0s
 ✔ Container netbox-docker-netbox-1               Stopped                                                                                                                 0.0s
 ✔ Container netbox-docker-redis-1                Stopped                                                                                                                 0.0s
 ✔ Container netbox-docker-postgres-1             Stopped                                                                                                                 0.0s
 ✔ Container netbox-docker-redis-cache-1          Stopped                                                                                                                 0.0s
? Going to remove netbox-docker-netbox-worker-1, netbox-docker-netbox-housekeeping-1, netbox-docker-netbox-1, netbox-docker-postgres-1, netbox-docker-redis-1, netbox-docker-redis-cache-1 Yes
[+] Running 6/0
 ✔ Container netbox-docker-netbox-worker-1        Removed                                                                                                                 0.0s
 ✔ Container netbox-docker-redis-cache-1          Removed                                                                                                                 0.0s
 ✔ Container netbox-docker-netbox-housekeeping-1  Removed                                                                                                                 0.0s
 ✔ Container netbox-docker-netbox-1               Removed                                                                                                                 0.0s
 ✔ Container netbox-docker-redis-1                Removed                                                                                                                 0.0s
 ✔ Container netbox-docker-postgres-1             Removed                                                                                                                 0.0s

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.

See more guides:

Cart

Your Cart is Empty

Back To Shop