Docker - 0victor0/pyping2 GitHub Wiki
pyping2 with Docker
Contents
- Docker intro: some background on Docker
- Production: how to use Docker + pyping2 to run tests
1. Docker intro
Docker TL;DR
Docker is a virtualization platform that allows applications to run on any hardware that is running a Docker engine, regardless of host environment. The result is an infrastructure that allows an application to be run anywhere. In this case, even though the library is built on top of open source Linux binaries, you can run pyping2 on Windows, OSX, GNU/Linux, virtual machines, or even ARM machines.
Docker benefits
The power of Docker is that it makes tools and applications portable, without the need for setting up each machine, test. and reporting. For a network analysis library like pyping2, this is an ideal use case -- the library and tests can be developed and seamlessly deployed to different types of hardware in different locations. It is recommended to use a Docker on a Linux host or in a Linux VM -- for VMs, host OS should not impact performance. It is inadvisable to use Docker on OSX for pyping2.
Docker network
There are different network drivers to use, host network will bypass reporting the Docker VM IP and is as fast as host networking
Requirements:
- Network connection
- Docker v1.12 or later
We'll start with assuming your environment has all requirements.
This workflow will allow tests to run in Docker, copy to host, without ever needing to enter Docker container. If using a VM, it is recommended to do the Dockerized workflow in a shared folder with the host machine to enable shared access with host, VM, and Docker.
Build the environment
To build the environment, the image must be pulled from Docker Hub and a container created in order to use the library:
Pull image
docker pull victorclark/pyping2:latest
Build container
Now move to the directory where you have your CSV of URLs and build your container:
docker run -itd \ #start a container and run in the backround
--name pyping2_container \ #give the container a name
--net=host \ #specify host network adapter
-v $(pwd):/from_host \ #mount your current directory with CSV
victorclark/pyping2:latest #Use the pyping2 image
If all goes well, you should see the container ID printed. Note that if your CSV is in a shared folder from the host machine, any edits from the host machine will be read by Docker.
Run pyping2 on the CSV of URLs
Now we can run your tests with a single commandL
python -m pyping2 [your csv of URLs] [optional: name of your network interface]
You should see output similar to:
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
174 packets captured
174 packets received by filter
0 packets dropped by kernel
***Hit enter to continue on IPython....
***Performing lft on: www.docker.com
***Performing lft on: www.github.com
***Performing lft on: www.mozilla.org
***lft report generated: pyping2_results/2017_01_25/20_02_56.csv
***pcap written to: pyping2_results/2017_01_25/20_02_56.pcap
All results are written to the container, so we will need a way to copy them to the VM
Copy results to host
Copy the test results to your current directory with:
docker cp pyping2:/pyping2/pyping2_results/ .
Note if you are in a shared folder from the host, this will also copy to the host machine.
Stop and remove container:
How that the results have been copied, the containers can be stopped and removed. Containers are meant to be ephemeral; when you are done, stop and remove the container:
NOTE THAT ANY DATA NOT COPIED BEFORE REMOVING A CONTAINER WILL BE LOST
docker stop pyping2
docker rm pyping2
That's it for the Dockerized workflow!