侧边栏壁纸
博主头像
Lang博主等级

十七岁想打职业。

  • 累计撰写 10 篇文章
  • 累计创建 11 个标签
  • 累计收到 1 条评论
隐藏侧边栏

Docker常用组件容器启动

Lang
2021-11-08 / 0 评论 / 1 点赞 / 78 阅读 / 6,653 字
温馨提示:
本文最后更新于 2022-01-21,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

1.Docker 安装Mysql

docker run -p 3306:3306 --name mysql \
-v /usr/local/docker/mysql/conf:/etc/mysql \
-v /usr/local/docker/mysql/logs:/var/log/mysql \
-v /usr/local/docker/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=jy0107 \
-d mysql:5.7

2.Docker 安装Redis

redis.conf下载地址:http://download.redis.io/redis-stable/redis.conf

docker run -p 6380:6379 --name redis \
-v /usr/local/docker/redis/redis.conf:/etc/redis/redis.conf \
-v /usr/local/docker/redis/data:/data \
-d redis redis-server /etc/redis/redis.conf --appendonly yes

进入docker容器内部redis-cli

docker exec -it redis redis-cli

3.Docker 安装Nginx

先复制容器中的nginx.conf和conf.d到宿主机指定位置

sudo docker cp containerID:container_path host_path
docker run -d --name nginx -p 80:80 -p 443:443 -v \
/usr/local/docker/nginx/nginx.conf:/etc/nginx/nginx.conf -v \
/usr/local/docker/nginx/logs:/var/log/nginx -v \
/usr/local/docker/nginx/html:/usr/share/nginx/html -v \
/usr/local/docker/nginx/conf:/etc/nginx/conf.d nginx

4.Docker 安装Rabbitmq

docker run -d --name rabbitmq \
-e RABBITMQ_DEFAULT_USER=guest -e RABBITMQ_DEFAULT_PASS=guest \
-p 15672:15672 -p 5672:5672 rabbitmq

5.Docker 安装Nacos

官方文档:https://nacos.io/zh-cn/docs/quick-start-docker.html

安装单机模式mysql版5.7

1.克隆git项目
git clone https://github.com/nacos-group/nacos-docker.git
cd nacos-docker
1.1这里我使用的是自己的mysql数据库

nacos sql地址:https://github.com/alibaba/nacos/blob/master/distribution/conf/nacos-mysql.sql

(1)vim standalone-mysql-8.yaml
(2)注释了依赖的mysql镜像

(3)vim nacos-standlone-mysql.env

2.构建镜像和启动容器
docker-compose -f example/standalone-mysql-5.7.yaml up

docker-compose up:

构建,创建,重新创建,启动,连接服务的相关容器。所有连接的服务都会启动,除非它们已经运行
docker-compose up 命令会聚合所有容器的输出,当命令退出时,所有容器都会停止。使用docker-compose up -d可在后台启动并运行所有容器

docker-compose -f example/standalone-mysql-5.7.yaml up -d
3.采坑
WARNING: The version variable is not set. Defaulting to a blank string.
ERROR: no such image: nacos/nacos-server:: invalid reference format

vim example/standalone-derby.yaml 去修改 yaml 配置
将image: nacos/nacos-server:{}
修改为:image: nacos/nacos-server:latest

6.Docker 安装Minio

docker run -p 9000:9000 -p 9001:9001 --name minio \
-e "MINIO_ROOT_USER=admin" \
-e "MINIO_ROOT_PASSWORD=Zr123654" \
-v /usr/local/docker/minio/data:/data \
-v /usr/local/docker/minio/config:/root/.minio \
-d minio/minio server /data --console-address ":9001"

7.Docker 安装Elasticsearch

创建挂载的目录

mkdir -p /usr/local/docker/elasticsearch/config
mkdir -p /usr/local/docker/elasticsearch/data
echo "http.host: 0.0.0.0" >> /usr/local/docker/elasticsearch/config/elasticsearch.yml

创建容器并启动

docker run --name elasticsearch -p 9200:9200 -p 9300:9300  -e \
"discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx128m" -v \
/usr/local/docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v \
/usr/local/docker/elasticsearch/data:/usr/share/elasticsearch/data -v \
/usr/local/docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins -d elasticsearch:7.6.2

其中elasticsearch.yml是挂载的配置文件,data是挂载的数据,plugins是es的插件,如ik,而数据挂载需要权限,需要设置data文件的权限为可读可写,需要下边的指令。
chmod -R 777 要修改的路径

-e "discovery.type=single-node" 设置为单节点
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" \ 测试环境下,设置ES的初始内存和最大内存,否则导致过大启动不了ES

8.Docker 安装Kibana

docker run --name kibana \
-e ELASTICSEARCH_HOSTS=http://ESip地址:9200 -p 5601:5601 -d kibana:7.6.2

docker run --name kibana
-e ELASTICSEARCH_HOSTS=http://120.24.94.52:9200 -p 5601:5601 -d kibana:7.6.2

9.Docker 安装Zookeeper

docker run --privileged=true -d --name zookeeper --publish 2181:2181  -d zookeeper

10.Docker 安装Apollo

Config Service:

docker pull apolloconfig/apollo-configservice

docker run -d \
    --name apollo-configservice \
    --net=host \
    -v /tmp/logs:/opt/logs \
    -e SPRING_DATASOURCE_URL="jdbc:mysql://120.24.94.52:3306/ApolloConfigDB?characterEncoding=utf8" \
    -e SPRING_DATASOURCE_USERNAME=root \
    -e SPRING_DATASOURCE_PASSWORD=xxx \
    apolloconfig/apollo-configservice

Admin Service:

docker pull apolloconfig/apollo-adminservice

docker run -d \
    --name apollo-adminservice \
    --net=host \
    -v /tmp/logs:/opt/logs \
    -e SPRING_DATASOURCE_URL="jdbc:mysql://120.24.94.52:3306/ApolloConfigDB?characterEncoding=utf8" \
    -e SPRING_DATASOURCE_USERNAME=root \
    -e SPRING_DATASOURCE_PASSWORD=xxx \
    apolloconfig/apollo-adminservice

Portal Server:

docker pull apolloconfig/apollo-portal

docker run -d \
    --name apollo-portal \
    --net=host \
    -v /tmp/logs:/opt/logs \
    -e SPRING_DATASOURCE_URL="jdbc:mysql://120.24.94.52:3306/ApolloPortalDB?characterEncoding=utf8" \
    -e SPRING_DATASOURCE_USERNAME=root \
    -e SPRING_DATASOURCE_PASSWORD=xxx \
    -e APOLLO_PORTAL_ENVS=dev \
    -e DEV_META=http://120.24.94.52:8080 \
    apolloconfig/apollo-portal
version: "3"
 
services:
  apollo-configservice:                                         
    container_name: apollo-configservice               #      
    build: apollo-configservice/src/main/docker/       #dockerfile目录     
    image: apollo-configservice                        #镜像名
    restart: always                                    #异常重启
    hostname: apollo-configservice                     #本次使用内网Ip,也可以使用桥接/host(与此处hostname冲突)
    ports:                                             #端口
      - "8080:8080"    
    volumes:                                           #挂载日志目录
      - "/usr/local/docker/apollo//logs/configservice:/opt/logs/100003171"
    environment:                                       #数据库环境变量,在设置meta_server地址时并未设置,在构建镜像时设置即可
      - spring_datasource_url=jdbc:mysql://127.0.0.1:3306/ApolloConfigDB?characterEncoding=utf8
      - spring_datasource_username=root
      - spring_datasource_password=root
 
  apollo-adminservice:
    container_name: apollo-adminservice
    build: apollo-adminservice/src/main/docker/   
    image: apollo-adminservice                    
    ports:                                        
      - "8090:8090"
    restart: always                               
    hostname: apollo-adminservice                 
    depends_on:                                   #启动依赖
      - apollo-configservice
    volumes:
      - "/docker/apollo/logs/adminservice:/opt/logs/100003172"
    environment:
      - spring_datasource_url=jdbc:mysql://127.0.0.1:3306/ApolloConfigDB?characterEncoding=utf8
      - spring_datasource_username=root
      - spring_datasource_password=root
 
  apollo-portal:
    container_name: apollo-portal
    build: apollo-portal/src/main/docker/
    image: apollo-portal
    ports:
      - "8070:8070"
    restart: always
    hostname: apollo-portal     
    depends_on:
      - apollo-adminservice
    volumes:
      - "/docker/apollo/logs/portal:/opt/logs/100003173"
    environment:
      - spring_datasource_url=jdbc:mysql://127.0.0.1:3306/ApolloPortalDB?characterEncoding=utf8
      - spring_datasource_username=root
      - spring_datasource_password=root

11.Docker 安装portainer

docker run -d -p 9002:9000     --restart=always     -v \
/var/run/docker.sock:/var/run/docker.sock     --name prtainer-test \
portainer/portainer

12.Docker 安装Springboot项目

docker run -d  --name yr-cloud-blog --net=host registry.cn-hangzhou.aliyuncs.com/lang_io/yr_cloud_blog


docker run -d  --name yr-cloud-search --net=host registry.cn-hangzhou.aliyuncs.com/lang_io/yr_cloud_search

docker run -d  --name yr-cloud-im --net=host registry.cn-hangzhou.aliyuncs.com/lang_io/yr_cloud_im

docker run -d  --name yr-cloud-file --net=host registry.cn-hangzhou.aliyuncs.com/lang_io/yr_cloud_file

docker run -d  --name yr-cloud-system --net=host registry.cn-hangzhou.aliyuncs.com/lang_io/yr_cloud_system

docker run -d  --name yr_cloud_gateway --net=host registry.cn-hangzhou.aliyuncs.com/lang_io/yr_cloud_gateway

docker run -d  --name yr-cloud-clock2 --net=host TZ=Asia/Shanghai registry.cn-hangzhou.aliyuncs.com/lang_io/yr_cloud_clock
0

评论