The following post might look like running kafka cluster in MacOS but it basically shows how to get started with Docker and basic docker commands.
Docker is widely being used to simply spawn a service I need as a separate container just like in production. And It can easily be guessed same container can be run the production server with the same config.
For example, if my application uses MongoDB, traditionally I used to download and install MongoDB myself and test it. I remember in one of my analytics project, I had weird issue with running different version of Elasticsearch because each Software Engineer does his own stuff in a large team.
With docker, I can create an Elasticsearch container that my application would connect to and share the same container with other members in a team. And the same Elasticsearch container is spawn inside the Production server, so that configuration everywhere is the same.
Download and install docker native for mac
I will see following files in /Applications/
docker-compose is a tool for defining and running multi-container Docker apps.
Docker is widely being used to simply spawn a service I need as a separate container just like in production. And It can easily be guessed same container can be run the production server with the same config.
For example, if my application uses MongoDB, traditionally I used to download and install MongoDB myself and test it. I remember in one of my analytics project, I had weird issue with running different version of Elasticsearch because each Software Engineer does his own stuff in a large team.
With docker, I can create an Elasticsearch container that my application would connect to and share the same container with other members in a team. And the same Elasticsearch container is spawn inside the Production server, so that configuration everywhere is the same.
Download and install docker native for mac
wget https://download.docker.com/mac/stable/Docker.dmg hdiutil mount Docker.dmg ##pops up installer to cp into /Applications sudo cp -r /Volumes/Docker/Docker.app /Applications/ hdiutil unmount /Volumes/Docker
I will see following files in /Applications/
$ ls -l /Applications/Docker.app/Contents/ total 32 drwxr-xr-x 21 a1353612 admin 714 Oct 6 04:45 Frameworks -rw-r--r-- 1 a1353612 admin 2460 Oct 6 04:48 Info.plist drwxr-xr-x 4 a1353612 admin 136 Oct 6 04:45 Library drwxr-xr-x 11 a1353612 admin 374 Oct 6 04:48 MacOS -rw-r--r-- 1 a1353612 admin 8 Oct 6 04:45 PkgInfo drwxr-xr-x 26 a1353612 admin 884 Oct 6 04:48 Resources drwxr-xr-x 3 a1353612 admin 102 Oct 6 04:45 _CodeSignature -rw-r--r-- 1 a1353612 admin 7579 Oct 6 04:45 embedded.provisionprofile
Check its properly installed
docker --version Docker version 1.12.1, build 6f9534c docker-compose --version docker-compose version 1.8.0, build f3628c7 docker-machine --version docker-machine version 0.8.1, build 41b3b25
Test a webserver container is accessible from local.
Then send a GET request to localhost:8888
docker run -it --rm -p 8888:8080 tomcat:8.0
Then send a GET request to localhost:8888
$ curl -X GET localhost:8888 -i
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 22 Mar 2017 10:44:35 GMT
running a docker container
To run a docker container, I am cloning a kafka container, Kafka is a distributed messaging/streaming platform.
git clone https://github.com/prayagupd/docker-kafka-zk.git
cd docker-kafka-zk
docker-compose up -d
docker-compose is a tool for defining and running multi-container Docker apps.
Check the running containers
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4369c261f6d4 wurstmeister/zookeeper "/bin/sh -c '/usr/sbi" 48 seconds ago Up 45 seconds 22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp dockerkafkazk_zookeeper_1 6e83021e6c97 dockerkafkazk_kafka "start-kafka.sh" 48 seconds ago Up 46 seconds 0.0.0.0:32768->9092/tcp dockerkafkazk_kafka_1
Get the IP addresses for the containers
docker exec dockerkafkazk_kafka_1 cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.18.0.2 6e83021e6c97
or
docker inspect dockerkafkazk_kafka_1 | grep -w "IPAddress" "IPAddress": "", "IPAddress": "172.18.0.2",
and for zookeeper,
docker exec dockerkafkazk_zookeeper_1 cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.18.0.3 4369c261f6d4
SecureSHell to Kafka container from local machine
./start-kafka-shell.sh 172.18.0.2 172.18.0.3:2181 bash-4.3# echo $KAFKA_HOME/ /opt/kafka_2.11-0.10.0.1/
In next post, I will probably write about streaming to this kafka container using nodejs. I'm currently doing some stuffs on nodejs during my Masters period, (off office work). So, thinking of streaming via nodejs app which scala app would consume on the other side.
Resources
--------------
https://www.viget.com/articles/how-to-use-docker-on-os-x-the-missing-guide
https://docs.docker.com/docker-for-mac/networking/
--------------
https://www.viget.com/articles/how-to-use-docker-on-os-x-the-missing-guide
https://docs.docker.com/docker-for-mac/networking/
No comments:
Post a Comment