博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
开发环境中Docker的使用
阅读量:6086 次
发布时间:2019-06-20

本文共 5545 字,大约阅读时间需要 18 分钟。

一. Ubuntu16.04+Django+Redis+Nginx的Web项目Docker化

1.创建Django项目的image

# 创建项目image 执行 docker build -t ccnu_resource_pub -f docker/app/Dockerfile .#  把ubuntu:xenial作为基础镜像 如果不存在则pull远程FROM ubuntu:xenial#  把docker/common/sources.list 拷贝到镜像里的文件系统中ADD ./docker/common/sources.list /etc/apt/sources.list# 运行linux指令RUN apt-get -y update# PYTHON环境WORKDIR /proj# 把requirements.txt拷贝到/proj文件下ADD requirements.txt /projRUN apt-get install -y python python-dev python3 python3-dev python3-pipRUN apt-get install -y libmysqlclient-devRUN pip3 install --trusted-host pypi.python.org -r requirements.txtRUN pip3 install uwsgi#  ES日志目录RUN mkdir -p /var/log/ccnu_resourceRUN chmod -R 777 /var/log/ccnu_resource
View Code

 

2.创建Nginx的image

# 创建nginx的image  docker build -t ccnu_resource_pub_nginx -f docker/nginx/Dockerfile .FROM ubuntu:xenialADD ./docker/common/sources.list /etc/apt/sources.listRUN apt-get -y update && apt-get -y update --fix-missing && apt-get -y updateRUN apt-get install -y nginx
View Code

 

3.创建Redis的image

# 创建Redis的image   docker build -t ccnu_resource_pub_redis -f docker/redis/Dockerfile .FROM ubuntu:xenialADD ./docker/common/sources.list /etc/apt/sources.listRUN apt-get -y update && apt-get -y update --fix-missing && apt-get -y updateRUN apt-get install -y redis-server
View Code

 

4.创建docker-compose.yml

# version表示定义的 docker-compose.yml 文件内容所采用的版本,目前 Docker Compose 的配置文件已经迭代至了第三版version: "3"# docker-compose.yml 的核心部分,定义了容器的各项细节services:  redis:#  指定镜像    image: ccnu_resource_pub_redis:latest# 端口映射 最好使用引号将端口映射的定义包裹起来,由于 YAML 格式对 xx:yy 这种格式的解析有特殊性,在设置小于 60 的值时,会被当成时间而不是字符串来处理    ports:      - "6379:6379"    command: redis-server --appendonly yes    logging:      driver: "json-file"      options:        max-size: "200k"        max-file: "10"  web:    image: ccnu_resource_pub:latest    ports:      - "8000:8000"    command: python3 manage.py runserver 0.0.0.0:8000    logging:      driver: "json-file"      options:        max-size: "200k"        max-file: "10"# 以 Compose 配置文件为中心的相对路径作为数据卷挂载到容器    volumes:      - .:/proj# 依赖 表示启动web的compose前需先启动 redis    depends_on:      - redis  celery:    image: ccnu_resource_pub:latest    command: celery worker -A ccnu_resource -l info    logging:      driver: "json-file"      options:        max-size: "200k"        max-file: "10"    depends_on:      - web    volumes:      - .:/proj
View Code

 

二. 单机ELK部署Docker化

1. 进入ELK的docker网址(可能要FQ) ,选择最新稳定版6.54版

 

 使用官方提供的docker-compose.yml创建ES的docker-compose.yml

version: '2.2'services:  elasticsearch:    image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4    container_name: elasticsearch    environment:      - cluster.name=docker-cluster      - bootstrap.memory_lock=true      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"    ulimits:      memlock:        soft: -1        hard: -1    volumes:      - esdata1:/usr/share/elasticsearch/data    ports:      - 9200:9200    networks:      - esnet  elasticsearch2:    image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4    container_name: elasticsearch2    environment:      - cluster.name=docker-cluster      - bootstrap.memory_lock=true      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"      - "discovery.zen.ping.unicast.hosts=elasticsearch"    ulimits:      memlock:        soft: -1        hard: -1    volumes:      - esdata2:/usr/share/elasticsearch/data    networks:      - esnetvolumes:  esdata1:    driver: local  esdata2:    driver: localnetworks:  esnet:
View Code

 

2. 然后进入配置页面https://www.elastic.co/guide/en/logstash/6.5/docker-config.html, 查看Logstash的docker配置

logstash:     image: docker.elastic.co/logstash/logstash:6.5.4    container_name: logstash     networks:      - esnet    depends_on:         - elasticsearch        - elasticsearch2    environment:      - "LS_JAVA_OPTS=-Xms512m -Xmx512m"
View Code

 

3. 然后进入配置页面https://www.elastic.co/guide/en/kibana/6.5/docker.html, 查看Kibana的docker配置

kibana:    image: docker.elastic.co/kibana/kibana:6.5.4    container_name: kibana    ports:      - "5601:5601"    networks:      - esnet    depends_on:        - elasticsearch        - elasticsearch2
View Code

 

4. 整合docker-compose.ym

version: '2.2'services:  elasticsearch:    image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4    container_name: elasticsearch    environment:      - cluster.name=docker-cluster      - bootstrap.memory_lock=true      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"    ulimits:      memlock:        soft: -1        hard: -1    volumes:      - esdata1:/usr/share/elasticsearch/data    ports:      - 9200:9200    networks:      - esnet  elasticsearch2:    image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4    container_name: elasticsearch2    environment:      - cluster.name=docker-cluster      - bootstrap.memory_lock=true      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"      - "discovery.zen.ping.unicast.hosts=elasticsearch"    ulimits:      memlock:        soft: -1        hard: -1    volumes:      - esdata2:/usr/share/elasticsearch/data    networks:      - esnet  logstash:     image: docker.elastic.co/logstash/logstash:6.5.4    container_name: logstash     networks:      - esnet    depends_on:         - elasticsearch        - elasticsearch2    environment:      - "LS_JAVA_OPTS=-Xms512m -Xmx512m"  kibana:    image: docker.elastic.co/kibana/kibana:6.5.4    container_name: kibana    ports:      - "5601:5601"    networks:      - esnet    depends_on:        - elasticsearch        - elasticsearch2  volumes:  esdata1:    driver: local  esdata2:    driver: localnetworks:  esnet:
View Code

 

配置好后,执行sudo docker-compose up即可成功启动ELK

转载于:https://www.cnblogs.com/FG123/p/10091729.html

你可能感兴趣的文章
Flux OOM实例
查看>>
07-k8s-dns
查看>>
Android 中 ListView 分页加载数据
查看>>
oracle启动报错:ORA-00845: MEMORY_TARGET not supported on this system
查看>>
Go方法
查看>>
Dapper丶DapperExtention,以及AbpDapper之间的关系,
查看>>
搞IT的同学们,你们在哪个等级__那些年发过的帖子
查看>>
且谈语音搜索
查看>>
MySQL数据库导入导出常用命令
查看>>
低版本Samba无法挂载
查看>>
Telegraf+Influxdb+Grafana构建监控平台
查看>>
使用excel 展现数据库内容
查看>>
C#方法拓展
查看>>
MySql.Data.dll的版本
查看>>
Linux系统磁盘管理
查看>>
hdu 2191 (多重背包+二进制优化)
查看>>
home.php
查看>>
neo4j---删除关系和节点
查看>>
redis分布式锁redisson
查看>>
什么样的企业可以称之为初创企业?
查看>>