Home > Software > How to Deploy NetBox with Docker Compose: A Simplified Guide

How to Deploy NetBox with Docker Compose: A Simplified Guide

Anastasios Antoniadis

Master the deployment of NetBox using Docker Compose with our easy-to-follow guide. Ideal for network engineers and IT professionals, this tutorial offers a step-by-step approach to setting up NetBox in a Docker environment, ensuring a robust and scalable network management solution.

Docker (1)

NetBox is a widely used open-source web application that helps network engineers manage and document computer networks. It offers several features such as IP address management (IPAM), device and connection tracking. By combining NetBox with Docker Compose, network professionals can deploy and manage their network resources more efficiently. This guide provides a detailed walkthrough on deploying NetBox using Docker Compose, making the deployment process smooth and scalable.

Why Docker Compose?

Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services, networks, and volumes. It simplifies the Docker deployment process and ensures your application runs the same way everywhere. Docker Compose offers a manageable and straightforward solution for deploying an application like NetBox, which may require several services to run in conjunction.

Prerequisites

Before starting, ensure you have Docker and Docker Compose installed on your system. Familiarity with Docker, Docker Compose, and basic networking concepts is also beneficial.

Step 1: Create the Docker Compose File

Create a docker-compose.yml file in your preferred directory. This file will define the necessary services for running NetBox, including the NetBox application itself, a PostgreSQL database for data storage, and Redis for caching and queueing.

version: '3.7'

services:
  netbox:
    image: netboxcommunity/netbox:v3.1.1
    depends_on:
      - postgres
      - redis
    ports:
      - "8000:8080"
    environment:
      - DB_NAME=netbox
      - DB_USER=netbox
      - DB_PASSWORD=netbox
      - DB_HOST=postgres
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - SECRET_KEY=your_secret_key_here
    volumes:
      - netbox-static-files:/opt/netbox/netbox/static

  postgres:
    image: postgres:13
    environment:
      - POSTGRES_USER=netbox
      - POSTGRES_PASSWORD=netbox
      - POSTGRES_DB=netbox
    volumes:
      - postgres-data:/var/lib/postgresql/data

  redis:
    image: redis:6
    volumes:
      - redis-data:/data

volumes:
  postgres-data:
  redis-data:
  netbox-static-files:

Explanation of Docker Compose Components

  • version: Specifies the version of the Compose file format. Version 3.7 is used here for its broad support.
  • services: Defines three services required to run NetBox: netbox for the application itself, postgres for the database, and redis for caching and queueing.
  • image: Points to the Docker image for each service. Official images are used for PostgreSQL and Redis, and the NetBox community image for NetBox.
  • depends_on: Ensures that NetBox starts only after the PostgreSQL and Redis services are up.
  • ports: Exposes NetBox to the host machine on port 8000.
  • environment: Configures necessary environment variables for NetBox and PostgreSQL, including database credentials and the secret key for NetBox.
  • volumes: Maps persistent storage for the services, ensuring data is retained across container restarts.

Step 2: Deploying with Docker Compose

With the docker-compose.yml file ready, deploying NetBox is straightforward. Open a terminal, navigate to the directory containing your Docker Compose file, and execute:

docker compose up -d

This command will download the necessary Docker images, create the containers, and start the services in the background.

Step 3: Accessing NetBox

After the containers are up and running, you can access NetBox by navigating to http://localhost:8000 in your web browser. You should be greeted by the NetBox login page, where you can log in using the default credentials (unless changed in your configuration) and start managing your network documentation.

Netbox Docker Compose Log
Screenshot: BORDERPOLAR

Conclusion

Deploying NetBox with Docker Compose offers a streamlined, efficient approach to setting up a comprehensive network management and documentation tool. By following the steps in this guide, you can have a robust, scalable instance of NetBox that is up and running and ready to support your network engineering tasks. Whether you’re documenting a small office network or a large data center, integrating NetBox with Docker Compose simplifies network management, allowing you to focus on optimizing your network’s performance and reliability.

Anastasios Antoniadis
Follow me
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x