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.
- apt upgrade
- apt update
- apt install software-properties-common
- add-apt-repository ppa:deadsnakes/ppa
- apt install python3.9
- apt install python3-pip
- apt install nano
- pip3 install netmiko
- pip3 install rich
- pip3 install pyats[full]
Finally after installing the bare minimum that we need to get started.
- Create a new folder called network_automation
- create netmiko inside it
- 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
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.
2 thoughts on “Docker for Network Engineers Part III – Creating a custom docker image/container”