Monthly Archives: June 2020

Docker

Install docker on mac:

  1. brew install docker
  2. Download docker.dmg and install

Run jenkins in background
docker run -d -p 8080:8080 -p 50000:50000 jenkins

// 8080:80, host port 8080, container port 80

-d makes it to run background. Just like nohup

Run centos in docker
docker run -it centos /bin/bash

-it makes it run interactive mode,

Or below command to go into interactive mode:

docker exec -it <container_name> /bin/bash

List all docker container, including stopped ones

docker ps -a

Start a stopped container

docker start container_id

Enter docker container.

For example if container id 86289a1dad7c is centOS, this will make it into centos command line:

docker attach 86289a1dad7c

remove a container

docker container rm container_id

Create overlay network

docker network create -d overlay –attachable kafka-net

check CPU, memory, IO etc

docker stats container_id

Run nginx

docker run –name docker-container-name -p 8077:80 -d nginx

-d is background mode.

Connecting to into docker

docker exec -it CONTAINER_ID bash

Check Container network id, mode, ip

docker container inspect container_id

Build a docker image

docker build folder_name –tag pengli:1.0

This requires that Dockerfile exists in folder_name. Then it creates a docker image with tag name pengli, version 1.0.

After the docker image build, run “docker image ls” to show images in local
docker_image

docker container ls -a // check all containers, including stopped containers
docker container stop container_id // stop container
docker container rm container_id // remove container. Only stop first, then remove
docker run -p 80:80 –detach –name pengli pengli:1.0 // create a container with this image

Confluent connect to Kafka

kafka-console-producer -broker-list broker_ip:port –topic test
kafka-console-consumer -bootstrap-server broker_ip:port –topic test

Docker network

 

Bridge, normal one. It has a gateway, each container has its own IP.
host, each docker host can have only 1 container.
none, an isolation network.

docker_network

Overlay

The swarm has to live on overlay network. Such as this command “docker service create –network overlay_network –name=centos –replicas 2 centos”

Each container has same port number, so overlay network has an internal load balance to forward traffic.

docker_overlay

 

https://success.docker.com/article/getting-started-with-kafka

Install Kafka by docker:

  1. create a zk(zookeeper)
    docker service create –network kafka-net –name=zookeeper –publish 2181:2181 qnib/plain-zookeeper:2018-04-25
  2. create a zk UI
    docker service create –network kafka-net –name=zkui –publish 9090:9090 qnib/plain-zkui@sha256:30c4aa1236ee90e4274a9059a5fa87de2ee778d9bfa3cb48c4c9aafe7cfa1a13
  3. Create a broker
    docker service create –network kafka-net –name broker –hostname=”{{.Service.Name}}.{{.Task.Slot}}.{{.Task.ID}}” -e KAFKA_BROKER_ID={{.Task.Slot}} -e ZK_SERVERS=tasks.zookeeper qnib/plain-kafka –publish 9092:9092
  4. Scale up brokers
    docker service update –replicas=3 broker
  5. Create 3 brokers, with port mapping
    docker service create –network kafka-net –name broker –publish 9092:9092 –replicas 3 –hostname=”{{.Service.Name}}.{{.Task.Slot}}.{{.Task.ID}}” -e KAFKA_BROKER_ID={{.Task.Slot}} -e ZK_SERVERS=tasks.zookeeper qnib/plain-kafka

Mysql in docker

install mysql docker

docker pull mysql/mysql-server:latest

docker run –name container_name -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql

docker exec 24b5b77b3d5c mysql -uroot -ppassword -e ‘show databases;’