- First clone the
cna-code
repo from github
git clone http://github.com/intracom-telecom-sdn/cna-code.git
cd cna-code
The first component of our cloud native application is a basic HTTP server
implemented in server/main.go
.
This server exposes 2 REST endpoints
/doWork
: The server handles an incoming request to do a unit of work/stop
: The server exits.
-
Run server application
go run server/main.go
-
Perform a GET request using CURL and observe the result
curl -X GET http://localhost:4444/doWork
-
Try to run a second server on baremetal. You should get an error because the port the server is trying to bind is already in use. You can bypass this by making the user specify the port, but what about other resources? (config files, log files, system side effects)
-
Now stop the server
curl -X GET http://localhost:4444/stop
-
Open
server/Dockerfile
. This file is a template for a docker image to deploy and run our server application. -
Build the server image with
docker build -t cna-server:latest server/
-
Verify
cna-server
image exists withdocker images
-
Deploy a server instance container using
cna-server:latest
image. The-p
argument maps the internal port of the container4444
where the server is listening to port8000
in the hostdocker run -ti -p 8000:4444 --name server1 cna-server:latest
-
Verify container is up
docker ps
-
Inspect
server1
container. Search for IPAddress field to get the server IPdocker inspect server1
-
Make
server1
do some work with CURL using the IPAddress from step 6 and port 4444 (don't/stop
the server) -
Make
server1
do some work with CURL usinglocalhost
and port8000
-
Repeat steps 4-8 to create and test a new server instance named
server2
. Map to host port8001
. -
Delete
server2
instance
docker rm -f server2
Here we'll learn how to interact programmatically with Docker. This is the first step towards building an orchestrator that will provide some elasticity to our application.
We provide the boilerplate in Python.
We'll give you ~20 minutes for the coding part.
-
Implement the
TODOs
inorchestrator/python/docker_utils.py
. The functions in this module wrap the calls to Docker programmatic API and allow us to managecna-server
containers in an elastic and dynamic way -
Test the implementation inside Python REPL (bpython).
- We deployed and tested an application on baremetal. Does the trick, but somewhat inflexible.
- We deployed and tested the same application using Docker. We saw that Docker streamlines the deployment and destruction of application and makes it 100% reproduciple.