docker-compose的理解与使用
docker-compose是用来做docker集群管理的,也就是说我们可以通过它来管理docker
docker-compose讲解
执行docker-compose up 会读取docker-compose.yml中的配置文件来拉去镜像并构建和运行容器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| version: "3"
services: # 启动容器的名字 redis: # image意味着直接拉取对应的云端镜像来构建容器 image: redis:3.2 # 映射端口 ports: - "6379:6379" # 映射内外文件 volumes: - ./redis/conf:/usr/local/etc/redis/ - ./redis/data:/data - ./redis/log:/data/log command: redis-server /usr/local/etc/redis/redis.conf --appendonly yes
service: # 会调用 docker build -t Dockerfile来构建文件,默认是当前目录下 build: . volumes: - .:/data/code/ ports: - "18567:8567" dns: - 114.114.114.114 # 关联到之前的redis容器 depends_on: - redis
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| FROM ubuntu:16.04
ENV TZ "Asia/Shanghai" ENV TERM xterm
ADD deploy/sources.list /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y locales RUN locale-gen en_US.UTF-8 ENV LC_ALL=en_US.UTF-8 ENV LANG=en_US.UTF-8 ENV LANGUAGE=en_US.UTF-8 ENV TZ=:/etc/localtime
RUN apt-get install -y git wget curl bzip2
RUN mkdir -p /root/.pip/ ADD deploy/pip.conf /root/.pip/
RUN apt-get install -y build-essential libmysqlclient-dev libjpeg-dev libpng-dev zlib1g-dev libtiff-dev libtiff5 libfreetype6 \ libwebp-dev
RUN rm -rf /data/ && mkdir -p /data/ WORKDIR /data/
RUN curl -k https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh > /tmp/miniconda.sh && /bin/sh /tmp/miniconda.sh -b -f -p /data/miniconda3/ && rm -rf /tmp/miniconda.sh
ADD requirements.txt /data/ RUN /data/miniconda3/bin/pip install --no-cache-dir -r /data/requirements.txt RUN /data/miniconda3/bin/conda config --add channels conda-forge RUN /data/miniconda3/bin/conda install -y icu pcre libxml2 libiconv openssl jansson ca-certificates RUN /data/miniconda3/bin/conda install -y certifi || true RUN /data/miniconda3/bin/conda install -y uwsgi
RUN rm -rf /data/code/ && mkdir -p /data/code/
ENTRYPOINT ["/data/miniconda3/bin/uwsgi", "--ini", "/data/code/deploy/uwsgi.ini"]
|