- Install docker according to documentation
- Install docker-compose according to documentation
- Clone the repo from github
- Enter to the directory
control_docker_from_docker
We will assume that our System Under Test (SUT) is run using Tomcat. Therefore we will use tomcat docker image as our SUT image that we will use to build test image.
- Bring up
testimage (based on SUT image) and image with Robotframework (rfw) by executing:
$ docker-compose up This will build and pull all needed images (if needed), start them and bond in network. You can check containers are running by executing (in the dir where yml file is located):
$ docker-compose ps
Name Command State Ports
------------------------------------------------------------------
controldockerfromdocker_rfw_1 tail -f /dev/null Up
controldockerfromdocker_test_1 /test/run_all.sh UpYou can also visit localhost:8080 page to see tomcat's start page.
- Enter to
testcontainer and check if XML-RPC server is running:
$ docker exec -it controldockerfromdocker_test_1 bash
# python -m robotremoteserver test
Remote server running at http://127.0.0.1:8270.- Exit
testcontainer and enter therfwcontainer and execute tests:
$ docker exec -it controldockerfromdocker_rfw_1 bash
# cd /rfw/
# robot test.robot
==============================================================================
Test
==============================================================================
Print test distro version | PASS |
------------------------------------------------------------------------------
Print rfw distro version | PASS |
------------------------------------------------------------------------------
Restart Tomcat | PASS |
------------------------------------------------------------------------------
Test | PASS |
3 critical tests, 3 passed, 0 failed
3 tests total, 3 passed, 0 failed
==============================================================================
Output: /rfw/output.xml
Log: /rfw/log.html
Report: /rfw/report.htmlYou can see that 3 test cases were executed.
- Exit
rfwcontainer and copy test report to the host in order to view it in a browser:
$ docker cp controldockerfromdocker_rfw_1:/rfw/log.html .you can see that both "Print ..." test cases printed different Linux
distribution info. RFW container is based on Ubuntu and SUT/Test
(the one with tomcat) is based on Debian.
If you run on the host docker ps before test execution you will see
in the command output that both containers has been launched at the same time:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2e67cac31be4 controldockerfromdocker_test "/test/run_all.sh" 4 minutes ago Up 4 minutes controldockerfromdocker_test_1
91ac8e4716cf controldockerfromdocker_rfw "tail -f /dev/null" 4 minutes ago Up 4 minutes controldockerfromdocker_rfw_1But after executing test case you may notice that test container
was freshly started:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2e67cac31be4 controldockerfromdocker_test "/test/run_all.sh" 5 minutes ago Up 4 seconds controldockerfromdocker_test_1
91ac8e4716cf controldockerfromdocker_rfw "tail -f /dev/null" 5 minutes ago Up 5 minutes controldockerfromdocker_rfw_1- You can now stop and remove (option --remove-orphans) all containers:
docker-compose down --remove-orphans
Stopping controldockerfromdocker_test_1 ... done
Stopping controldockerfromdocker_rfw_1 ... done
Removing controldockerfromdocker_test_1 ... done
Removing controldockerfromdocker_rfw_1 ... doneRobotframework's Remote library with XML-RPC server are the answers to the question how to control dockerized application from within other dockerized application. Using this approach you can achieve much more:
- block network traffic on interfaces/ports
- create files
- control processes currently running in a container
- and many, many more
