Using Docker to Run Some Popular Application Images (MySql, ElasticSearch, RabbitMQ, Kafka, Zookeeper, Nginx, MongoDB, Tomcat) - NETSEC


Learning, Sharing, Creating

Cybersecurity Memo

Saturday, March 28, 2020

Using Docker to Run Some Popular Application Images (MySql, ElasticSearch, RabbitMQ, Kafka, Zookeeper, Nginx, MongoDB, Tomcat)

This post is only used to record some middleware projects' commands. I found that every time I need to start a lot of middleware on Windows is particularly troublesome. I thought of writing an article to summarize the commands which need to run in docker to start those middlewares. Next time just copy and paste the commands.

Docker starts MySQL

Search Mysql image

docker search mysql
View all images
  docker images -a

Run Mysql

 docker run -p 3306:3306 --name mysql -v $PWD /conf:/etc/mysql/conf.d -v $PWD /logs:/logs -v $PWD /data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD = 123456 -d mysql:5.7.19
  • -p 3306:3306 : Maps the container's 3306 port to the host's 3306 port.
  • -v $PWD/conf:/etc/mysql/conf.d : Mount conf/my.cnf host's current directory to the container's /etc/mysql/my.cnf .
  • -v $PWD/data:/var/lib/mysql : Mount the data directory under the host's current directory to the container's /var/lib/mysql .
  • -e MYSQL_ROOT_PASSWORD=root : Initialize the password of the root user.
View running containers
 docker ps
Into container content
 docker run -it mysql /bin/bash
log in
 mysql -u root -p
Modify permissions
This sentence is very crucial, clear the cache
 flush privileges;

Docker Launch ElasticSearch

Pull version source
 docker pull

Running elasticsearch with Docker

The default port of ElasticSearch is 9200 We map the host environment port 9200 port 9200 in the Docker container, and we can access the ElasticSearch service in the Docker container. At the same time, we name this container es.
 docker run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node"

Enter container configuration cross domain

Because you want to configure it, you need to enter the container to modify the corresponding configuration information.
 docker exec -it es /bin/bash
Enter operation
 # list file
 LICENSE.txt README.textile config lib modules NOTICE.txt bin data logs plugins 
#  Enter configuration folder
cd config 
# list file
elasticsearch.keystore ingest-geoip roles.yml users_roles elasticsearch.yml jvm.options role_mapping.yml users 
# Edit configuration file
vi elasticsearch.yml 
#  Add cross domain configuration
http.cors.enabled: true http.cors.allow-origin: "*"
As the configuration has been modified, the ElasticSearch container needs to be restarted.
 docker restart es

Docker Launch ElasticSearch-Head

Official Website:

 ddocker pull mobz/elasticsearch-head:5
Run the container
 docker run -d --name es_admin -p 9100:9100 mobz/elasticsearch-head:5

Docker Launch Redis

 docker run -p 6379:6379 --name redis -v /docker/redis/redis.conf:/etc/redis/redis.conf -v /docker/redis/data:/data -d redis redis-server /etc/redis/redis.conf

 > docker run redis # run Redis from docker
-p 6379:6379 # map local 6379 to docker's 6379 port. Front one is local port.
--name redis # set docker name as redis. It will be easier to manage it using docker ps 
-v /docker/redis/redis.conf:/etc/redis/redis.conf # link lock docker/redis/redis.conf file to docker's file /etc/redis/redis.conf
-v /docker/redis/data:/data # 关联本地/docker/redis/data到容器内/data目录,此为存放redis数据的目录,为方便以后升级redis,而数据可以留存 
-d # 后台启动,使用此方式启动,则redis.conf中daemonize必须设置为no,否则会无法启动 
redis-server /etc/redis/redis.conf # 在容器内启动redis-server的命令,主要是为了加载配置
 docker run --name redis_zl -p 6379:6379 -d redis --requirepass "密码"

Docker Launch RabbitMQ

 docker pull rabbitmq:management

 docker run -d --hostname my-rabbit --name rabbit -p 8080:15672 rabbitmq:management
 docker run -d -p 5672:5672 -p 15672:15672 --name rabbitmq rabbitmq:management
–Hostname: specify the container host name 
–name: specify the container name
-p: Map mq port number to local

Alternate startup sets both user and password
docker run -d --hostname my-rabbit --name rabbit -e RABBITMQ_DEFAULT_USER = admin -e RABBITMQ_DEFAULT_PASS = admin -p 15672:15672 -p 5672:5672 -p 25672:25672 -p 61613:61613 -p 1883:1883 rabbitmq:management 
15672: Console port number
5672: Application access port number
Reminder, if this started container is not stopped when the computer is shut down, it will not be able to access 15672 when restarting docker. At this time, just stop and remove the container, then restart docker, and re-execute the rabbitmq container command. .


Docker starts kafka and zookeeper

docker pull wurstmeister/kafka
docker pull wurstmeister/zookeeper
Start zookeeper
docker run -d --name zookeeper -p 2181:2181 -t wurstmeister/zookeeper docker run -d --name kafka \ -p 9092:9092 \ -e KAFKA_BROKER_ID = 0 \ -e KAFKA_ZOOKEEPER_CONNECT = \ -e KAFKA_ADVERTISED_LISTENERS = PLAINTEXT:// \ -e KAFKA_LISTENERS = PLAINTEXT:// -t wurstmeister/kafka

Docker starts Nginx

docker pull nginxdocker images | grep nginxdocker run --name nginx -p 80:80 -d nginxdocker exec -it nginx bash

Docker launches Mongodb

sudo docker pull mongo sudo docker run --name some-mongo -p 27017:27017 -d mongo --auth
 docker exec -it some-mongo bash
  • Start mongo
  • Switch
 use admin
Add users and permissions
 db.createUser ( { user: "root" , pwd: "root" , roles: [ { role: "userAdminAnyDatabase" , db: "admin" } ] } )

Docker launches Tomcat


docker images #list all images
docker image tomcat:7 #get the image from repository tomcat:7
docker run -d --name tomcat -p 8081:8080 tomcat:7

No comments:

Post a Comment