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 III – Creating a custom docker image/container

Posted on September 12, 2021September 14, 2021 by Gurpreet Kochar
Docker for Network Engineers Part I – An Introduction
Docker for Network Engineers Part II – Installation and Basic Usage

In this post on Docker for Network Engineers,

From the ubuntu container that we created in the last post, we will now customize the container to install all the base dependencies that we need for our project.

  1. apt upgrade
  2. apt update
  3. apt install software-properties-common
  4. add-apt-repository ppa:deadsnakes/ppa
  5. apt install python3.9
  6. apt install python3-pip
  7. apt install nano
  8. pip3 install netmiko
  9. pip3 install rich
  10. pip3 install pyats[full]

Finally after installing the bare minimum that we need to get started.

  1. Create a new folder called network_automation
  2. create netmiko inside it
  3. place the script file in that folder but this could be anything. Since we are focusing on docker for network engineers, we will put a python script that interacts with cisco devnet sandbox devices to pull some information and display on screen as shown below. This script can be found here
Multithreading with Python for Network Engineers
root@703ec162bc09:/# ls -l network_automation/netmiko/
total 4
-rw-r--r-- 1 root root 1277 Aug 16 01:34 netmiko_threading.py
root@703ec162bc09:/#

4. Execute the python script from within the container

root@703ec162bc09:/network_automation/netmiko# python3 netmiko_threading.py
sandbox-nxos-1.cisco.com
************************
{'platform': {'name': 'Nexus', 'os': 'NX-OS', 'software': {'system_version': '9.3(3)', 'system_image_file': 'bootflash:///nxos.9.3.3.bin', 'system_compile_time': '12/22/2019 2:00:00 [12/22/2019 14:00:37]'}, 'hardware': {'model': 'Nexus9000 C9300v', 'chassis': 'Nexus9000 C9300v', 'slots': 'None', 'rp': 'None', 'cpu': 'Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz', 'memory': '16408984 kB', 'processor_board_id': '9N3KD63KWT0', 'device_name': 'nxos_only', 'bootflash': '4287040 kB'}, 'kernel_uptime': {'days': 19, 'hours': 7, 'minutes': 24, 'seconds': 41}, 'reason': 'Unknown'}}
sandbox-iosxe-latest-1.cisco.com
********************************
{'version': {'xe_version': '17.03.01a', 'version_short': '17.3', 'platform': 'Virtual XE', 'version': '17.3.1a', 'image_id': 'X86_64_LINUX_IOSD-UNIVERSALK9-M', 'label': 'RELEASE SOFTWARE (fc3)', 'os': 'IOS-XE', 'image_type': 'production image', 'compiled_date': 'Wed 12-Aug-20 00:16', 'compiled_by': 'mcpre', 'rom': 'IOS-XE ROMMON', 'hostname': 'ios-xe-mgmt-latest.cisco.com-3', 'uptime': '4 days, 2 hours, 27 minutes', 'uptime_this_cp': '4 days, 2 hours, 29 minutes', 'returned_to_rom_by': 'reload', 'system_image': 'bootflash:packages.conf', 'last_reload_reason': 'reload', 'license_level': 'ax', 'license_type': 'N/A(Smart License Enabled)', 'next_reload_license_level': 'ax', 'chassis': 'CSR1000V', 'main_mem': '715705', 'processor_type': 'VXE', 'rtr_type': 'CSR1000V', 'chassis_sn': '9ESGOBARV9D', 'number_of_intfs': {'Gigabit Ethernet': '3'}, 'mem_size': {'non-volatile configuration': '32768', 'physical': '3978436'}, 'disks': {'bootflash:.': {'disk_size': '6188032', 'type_of_disk': 'virtual hard disk'}}, 'curr_config_register': '0x2102'}}
sandbox-iosxr-1.cisco.com
*************************
{'operating_system': 'IOSXR', 'software_version': '6.5.3', 'device_family': 'IOS-XRv 9000', 'uptime': '1 day 20 hours 49 minutes'}
root@703ec162bc09:/network_automation/netmiko#
root@703ec162bc09:/network_automation/netmiko#
root@703ec162bc09:/network_automation/netmiko#

5. Build an image out of this container

Pre Commit docker images

Post-Commit docker images

Clearly, you can see that now we have an image named network_automation tagged latest because we did not specify a custom tag from the container that we were working on. This is like a snapshot of the state of your container that you can distribute to others.

Let’s stop the currently running docker and build a container from the image that we just saved to verify everything is fine.

If you look closely, it took the docker container only a few seconds to launch itself and execute the python code to get the output we desired. If this would have been a snapshot of a VM, .ova, or something, it would have taken a really long time to achieve the same result with very little resources being required by a container to run.

Now that we have the basics right of docker and how it operates and what it does. Let’s see a little more advanced stuff like What is a DockerFile and how to use it in the following blog posts.

Docker for Network Engineers Part IV – What is a Dockerfile

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

2 thoughts on “Docker for Network Engineers Part III – Creating a custom docker image/container”

  1. Pingback: Docker for Network Engineers Part IV - What is a Dockerfile
  2. Pingback: Docker for Network Engineers Part II - Installation and Basic Usage – Network Automation

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