Docker run projects of common middleware

Disclaimer : This chapter only run as a front-end time recording project, found that every time you need to start a lot of middleware, particularly troublesome in the Windows start thinking about writing an article to sum up, all the middleware put it all started on the server, the next direct copy paste command enough.

For Redisexample: MongoDB, RabbitMQ Consul nginx, ,Tomcat

Here is the command

Docker start MySQL

search for

docker search mysql  

See all mirrors

 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: Map of the container port 3306 to port 3306 on the host.
  • -v $PWD/conf:/etc/mysql/conf.d: The host in the current directory conf/my.cnfto mount to container /etc/mysql/my.cnf.
  • -v $PWD/data:/var/lib/mysql: The data in the directory hosts directory is mounted to the container /var/lib/mysql.
  • -e MYSQL_ROOT_PASSWORD=root: Initialize the root user password.

View running container

docker ps

Into the container contents

docker run -it mysql /bin/bash

log in

mysql -u root -p

Modify permissions

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

This sentence is the key word, clear the cache

flush privileges;

Docker start ElasticSearch

Pull version Source https://www.docker.elastic.co/#

docker pull docker.elastic.co/elasticsearch/elasticsearch:6.3.2

Docker run elasticsearch

The default port ElasticSearch is 9200, we put the host environment 9200port mapping to Docker container 9200port, you can have access to the Docker containers ElasticSearch service, and at the same time we put this vessel named es.

docker run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.3.2

Configuring Inter into the container

Due to the configuration, it is necessary to enter the container which modify the configuration information.

docker exec -it es /bin/bash

Enter operation

# 显示文件
ls
结果如下:
LICENSE.txt  README.textile  config  lib   modules
NOTICE.txt   bin             data    logs  plugins

# 进入配置文件夹
cd config

# 显示文件
ls
结果如下:
elasticsearch.keystore  ingest-geoip  log4j2.properties  roles.yml  users_roles
elasticsearch.yml       jvm.options   role_mapping.yml   users

# 修改配置文件
vi elasticsearch.yml

# 加入跨域配置
http.cors.enabled: true
http.cors.allow-origin: "*"

Restart
due to changes in the configuration, it is necessary to restart ElasticSearch container.

docker restart es

Docker 部署 ElasticSearch-Head

Official website: https://github.com/mobz/elasticsearch-head

ddocker pull mobz/elasticsearch-head:5

Run container

docker run -d --name es_admin -p 9100:9100 mobz/elasticsearch-head:5

Docker start 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 

Explanation



> docker run redis # 从redis镜像运行容器
-p 6379:6379 # 映射本地6379端口到容器6379端口,前为本地端口
--name redis # 设置容器名称为redis,方便以后使用docker ps进行管理
-v /docker/redis/redis.conf:/etc/redis/redis.conf # 关联本地/docker/redis/redis.conf文件到容器中/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 start RabbitMQ

docker pull rabbitmq:management

run

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: Host name specified container
-name: Specifies the container name
-p: The port number mapped to the local mq

Alternate start and set 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

A reminder, if you turn off the computer when not stopped the start of the container, there will be cases inaccessible 15672 at startup docker again, then just stop and remove the container, and then restart a docker, re-execute the command to start a container rabbitmq .

Docker start 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=172.16.65.243:2181 \
    -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://172.16.65.243:9092 \
    -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -t wurstmeister/kafka

Docker start Nginx

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

Docker start 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
mongo

  • Switch
use admin

Adding Users and Privileges

db.createUser({ user: "root", pwd: "root", roles: [{ role: "userAdminAnyDatabase", db: "admin" }] })

Tomcat

docker images #查看所有镜像
docker image tomcat:7  #查看REPOSITORY为tomcat:7的镜像

docker run -d --name tomcat -p 8081:8080 tomcat:7

Published 75 original articles · won praise 183 · views 60000 +

Guess you like

Origin blog.csdn.net/qq_42897427/article/details/105037779