开发环境中Docker的使用
生活随笔
收集整理的這篇文章主要介紹了
开发环境中Docker的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一. 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 /proj RUN apt-get install -y python python-dev python3 python3-dev python3-pip RUN apt-get install -y libmysqlclient-dev RUN pip3 install --trusted-host pypi.python.org -r requirements.txt RUN pip3 install uwsgi# ES日志目錄 RUN mkdir -p /var/log/ccnu_resource RUN 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.list RUN 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 yeslogging:driver: "json-file"options:max-size: "200k"max-file: "10"web:image: ccnu_resource_pub:latestports:- "8000:8000"command: python3 manage.py runserver 0.0.0.0:8000logging:driver: "json-file"options:max-size: "200k"max-file: "10" # 以 Compose 配置文件為中心的相對路徑作為數據卷掛載到容器volumes:- .:/proj# 依賴 表示啟動web的compose前需先啟動 redisdepends_on:- rediscelery:image: ccnu_resource_pub:latestcommand: celery worker -A ccnu_resource -l infologging:driver: "json-file"options:max-size: "200k"max-file: "10"depends_on:- webvolumes:- .:/proj View Code?
二. 單機ELK部署Docker化
1. 進入ELK的docker網址(可能要FQ) https://www.docker.elastic.co/,選擇最新穩定版6.54版
?
?使用官方提供的docker-compose.yml創建ES的docker-compose.yml
version: '2.2' services:elasticsearch:image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4container_name: elasticsearchenvironment:- cluster.name=docker-cluster- bootstrap.memory_lock=true- "ES_JAVA_OPTS=-Xms512m -Xmx512m"ulimits:memlock:soft: -1hard: -1volumes:- esdata1:/usr/share/elasticsearch/dataports:- 9200:9200networks:- esnetelasticsearch2:image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4container_name: elasticsearch2environment:- cluster.name=docker-cluster- bootstrap.memory_lock=true- "ES_JAVA_OPTS=-Xms512m -Xmx512m"- "discovery.zen.ping.unicast.hosts=elasticsearch"ulimits:memlock:soft: -1hard: -1volumes:- esdata2:/usr/share/elasticsearch/datanetworks:- esnetvolumes:esdata1:driver: localesdata2: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.4container_name: logstash networks:- esnetdepends_on: - elasticsearch- elasticsearch2environment:- "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.4container_name: kibanaports:- "5601:5601"networks:- esnetdepends_on:- elasticsearch- elasticsearch2 View Code?
4. 整合docker-compose.ym
version: '2.2' services:elasticsearch:image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4container_name: elasticsearchenvironment:- cluster.name=docker-cluster- bootstrap.memory_lock=true- "ES_JAVA_OPTS=-Xms512m -Xmx512m"ulimits:memlock:soft: -1hard: -1volumes:- esdata1:/usr/share/elasticsearch/dataports:- 9200:9200networks:- esnetelasticsearch2:image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4container_name: elasticsearch2environment:- cluster.name=docker-cluster- bootstrap.memory_lock=true- "ES_JAVA_OPTS=-Xms512m -Xmx512m"- "discovery.zen.ping.unicast.hosts=elasticsearch"ulimits:memlock:soft: -1hard: -1volumes:- esdata2:/usr/share/elasticsearch/datanetworks:- esnetlogstash: image: docker.elastic.co/logstash/logstash:6.5.4container_name: logstash networks:- esnetdepends_on: - elasticsearch- elasticsearch2environment:- "LS_JAVA_OPTS=-Xms512m -Xmx512m"kibana:image: docker.elastic.co/kibana/kibana:6.5.4container_name: kibanaports:- "5601:5601"networks:- esnetdepends_on:- elasticsearch- elasticsearch2volumes:esdata1:driver: localesdata2:driver: localnetworks:esnet: View Code?
配置好后,執行sudo docker-compose up即可成功啟動ELK
轉載于:https://www.cnblogs.com/FG123/p/10091729.html
總結
以上是生活随笔為你收集整理的开发环境中Docker的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IIS 7.5关闭.net程序DEBUG
- 下一篇: Spring Boot参数校验