docker
搭建常用开发环境
docker
环境初始化
1. 安装常用工具
本文采用
centos7
的linux
环境 , 直接使用VM ware workstation
创建虚拟机 ; 因为用于开发环境 , 都是单机部署 .yum -y install curl net-tools vim
2. 安装 docker
, 采用的阿里云源
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io
systemctl start docker
1. consul
- 下载
consul
镜像docker pull consul
- 构建
consul
服务器docker run -d -p 8500:8500 --restart=always --name consul-server-01 --privileged=true --net=host -v /usr/local/servers/consul/data/server-01:/consul/data -v /usr/local/servers/consul/conf/server-01:/consul/config consul agent -server -bootstrap -ui -node=consul-server-01 -bind=192.168.184.128 -client='0.0.0.0'
- 构建
consul
客户端docker run -d -p 8500:8500 --restart=always --name consul-client-01 --privileged=true --net=host -v /usr/local/servers/consul/data/client-01:/consul/data -v /usr/local/servers/consul/conf/client-01:/consul/config consul agent -node=consul-client-01 -bind=192.168.184.129 -join=192.168.184.128 -client='0.0.0.0'
- 验证效果
浏览器访问
http://192.168.184.128:8500
2. ES
- 下载
ES
镜像 , 这里采用的7.1.1
版本docker pull elasticsearch:7.1.1
- 构建
ES
服务器因为
ES
默认采用2g
内存 , 所以这里得限制一下 , 否则容易弄崩环境 .docker run -d -p 9200:9200 -p 9300:9300 --restart=always --name es --privileged=true -e 'discovery.type=single-node' -e ES_JAVA_OPTS="-Xms512m -Xmx512m" elasticsearch:7.1.1
- 安装
IK
中文分词docker exec -it es bash ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.1.1/elasticsearch-analysis-ik-7.1.1.zip docker restart es
- 验证分词效果
curl -X POST "http://192.168.184.128:9200/_analyze" -H "Content-Type:application/json" -d '{"analyzer":"ik_max_word","text":"中华人民共和国"}'
3. redis
- 下载
redis
镜像docker pull redis
- 构建
redis
服务器因为这里采用了自定义配置文件启动 , 要先在宿主机对应目录创建
redis.conf
docker run -d -p 6379:6379 --restart=always --name redis --privileged=true -v /usr/local/servers/redis/redis.conf:/etc/redis/redis.conf -v /usr/local/servers/redis/data:/data -v /usr/local/servers/redis/logs:/data/logs redis redis-server /etc/redis/redis.conf
4. mongo
- 下载
mongo
镜像docker pull mongo
- 构建
mongo
服务器因为这里采用了自定义配置文件启动 , 要先在宿主机对应目录创建
mongo.conf
docker run -d -p 27017:27017 --restart=always --name mongo --privileged=true -v /usr/local/servers/mongo/data:/data/mongo/data -v /usr/local/servers/mongo/conf:/data/mongo/conf mongo -f /data/mongo/conf/mongo.conf
5. mysql
- 下载
mysql
镜像docker pull mysql
- 构建
mysql
服务器因为这里采用了自定义配置文件启动 , 要先在宿主机对应目录创建
my.cnf
docker run -d -p 3306:3306 --restart=always --name mysql --privileged=true -e MYSQL_ROOT_PASSWORD=123456 -v /usr/local/servers/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /usr/local/servers/mysql/data:/var/lib/mysql -v /usr/local/servers/mysql/log:/logs mysql
6. nginx
- 下载
nginx
镜像docker pull nginx
- 构建
nginx
服务器因为这里采用了自定义配置文件启动 , 要先在宿主机对应目录创建
nginx.conf
docker run -d -p 8080:80 --restart=always --name --privileged=true -v /usr/local/servers/nginx/log:/var/log/nginx -v /usr/local/servers/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/servers/nginx/conf.d:/etc/nginx/conf.d -v /usr/local/servers/nginx/html:/usr/share/nginx/html nginx
7. tomcat
- 下载
tomcat
镜像docker pull tomcat
- 构建
tomcat
服务器docker run -d -p 8081:8080 --restart=always --name tomcat --privileged=true -v /usr/local/servers/tomcat/webapps:/usr/local/tomcat/webapps tomcat
8. kafka
- 下载
kafka
镜像docker pull wurstmeister/kafka docker pull wurstmeister/zookeeper docker pull sheepkiller/kafka-manager
- 构建
kafka
服务器docker run -d -p 2181:2181 --restart=always --name zk --privileged=true wurstmeister/zookeeper docker run -d -p 9092:9092 --restart=always --name kafka --privileged=true -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=192.168.184.128:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.184.128:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 wurstmeister/kafka docker run -d -p 9000:9000 --restart=always --name kafka-manager --privileged=true --link zookeeper:zookeeper --link kafka:kafka --env ZK_HOSTS=zookeeper:2181 sheepkiller/kafka-manager
9. git 仓库
1.gitbucket
(推荐)
- 下载
gitbucket
镜像docker pull gitbucket/gitbucket
- 构建
gitbucket
服务器要先在宿主机创建目录
gitbucket
,同时开放端口8080
和29418
,29418
是采用ssh
时的端口.有条件可以使用https
,配置证书更安全docker run -d -p 8080:8080 -p 29418:29418 --name gitbucket -v /usr/local/servers/gitbucket/:/gitbucket --restart always --privileged=true gitbucket/gitbucket
访问地址
http://192.168.35.132:8080/
,默认账号和密码是root/root
2.gitlab
(不推荐,占用内存太大)
- 下载
gitlab
镜像docker pull gitlab/gitlab-ce
- 构建
gitlab
服务器docker run -d -p 9980:80 -p 9922:22 -v /usr/local/servers/gitlab/config:/etc/gitlab -v /usr/local/servers/gitlab/log:/var/log/gitlab -v /usr/local/servers/gitlab/data:/var/opt/gitlab --restart always --privileged=true --name gitlab gitlab/gitlab-ce
要先在宿主机创建目录
gitlab/log
,gitlab/config
,gitlab/data
,同时开放对应端口9980
和9922
其次需要修改访问地址指向宿主机,这3个参数:external_url
,gitlab_rails['gitlab_ssh_host']
,gitlab_rails['gitlab_shell_ssh_port']
gitlab访问地址,端口不写的话默认为80端口
external_url ‘http://192.168.35.132:9980’
ssh主机ip
gitlab_rails[‘gitlab_ssh_host’] = ‘192.168.35.132’
ssh连接端口
gitlab_rails[‘gitlab_shell_ssh_port’] = 9922
docker exec -it gitlab /bin/bash vi /etc/gitlab/gitlab.rb