Skip to content

Network Automation

My journey with Network & Cloud Automation

Menu
  • Beginner
  • DevOps-NetDevOps
  • Network Automation
    • Docker
    • Python Libraries
      • NAPALM
      • Netmiko
      • Jinja2
      • Scrapli
      • Yang
  • Cloud Automation
    • Terraform
  • Python 🐍 Tips and Tricks
Menu
docker for network engineers

Docker for Network Engineers Part IV – What is a Dockerfile

Posted on September 14, 2021September 14, 2021 by Gurpreet Kochar

We have seen the manual method of creating a container from an image and an image back from a container after you have done all the customizations. What if there is a more automated way of doing this. We can achieve the same end goal by using a DockerFile.

Docker for Network Engineers Part I – An Introduction
Docker for Network Engineers Part II – Installation and Basic Usage
Docker for Network Engineers Part III – Creating a custom docker image/container

What is DockerFile?

Dockerfile is nothing but a set of instructions or the set of commands you would like to be executed in your container before it’s packaged into an image. For example

  1. Download ubuntu docker image
  2. execute apt update
  3. apt upgrade
  4. apt install nano
  5. create a folder named network_automation
  6. copy a demo text file from you local OS into the network_automation folder of the cotainer
  7. and then build the image which can be distribubted. We have seen the manual method in post III of this series.

Let’s see how we can automate that process using a Dockerfile.

I have opened the current working directory of the host OS in VScode to write Dockerfile.

Highlighted in PINK are the keywords that serve as instructions for the docker build server.

Execute docker build command to make an image out of the instructions in the Dockerfile

Once the build process is completed, we can check docker images to verify my-multi-container is created and docker ps shows no running container at the moment.

Let’s run this image inside a container to see what it has in it.

So now instead of sharing the network_automation image that we built in the last post which was more than a Gig in size, we can share this Dockerfile instead which is only bytes in size and they can build the exact same container as you have when you started working on your project. Instead of sharing the Dockerfile, you could upload the image you built on DockerHub or any other cloud for people to use directly or as a base for their project.

For example, for the purpose of network automation, we need at least below dependencies

  1. Base image ( ubuntu most probably )
  2. nano text editor
  3. apt-get update && apt-get upgrade
  4. install python
  5. install pip
  6. install python libraries that we need for automation like netmiko, napalm, nornir, etc etc

All this could be dockerized as a template for network engineers to start working without they needing to build it from scratch. In fact, if you look on docker hub for network automation, you will surely find images that you can directly leverage for network automation, and it’s highly likely they might have some code samples in it too.

Know someone who may benefit? Share this:

  • Tweet
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to email a link to a friend (Opens in new window) Email
  • More
  • Click to print (Opens in new window) Print
  • Click to share on Reddit (Opens in new window) Reddit
  • Share on Tumblr
  • Pocket

Like this:

Like Loading...

Related

Leave a ReplyCancel reply

All Blog Posts
My Resume

Upcoming Posts

Sorry - nothing planned yet!

Recent Posts

  • How to backup configuration to TFTP Server using Ansible – Part II
  • How to backup network devices using Ansible – Part I
  • Netmiko SSH Proxy/JumpServer
  • A short note on SASE
  • Understanding Ansible

Recent Comments

  1. Jack on Multithreading with Python for Network Engineers
  2. LifeCanvas on [Theory] Multithreading vs Multiprocessing vs AsyncIO
  3. Jasper Horng on Netmiko SSH Proxy/JumpServer
  4. asdfasdf on Python API Using FASTAPI – UPDATE – PUT – PATCH – Part V
  5. Gurpreet Kochar on Python Scrapli AsyncIO Usage

Archives

  • September 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
Topic Request / Suggestion
Loading
© 2025 Network Automation | Powered by Minimalist Blog WordPress Theme
 

Loading Comments...
 

    %d