docker系列:Dockerfile 与 docker-compose应用

Dockerfile 与 docker-compose应用

介绍

搭建小工具使用时,python3.8.1在centos8各种错误,习惯了centos7, 真是折磨人,于是就用docker构建,解决环境的问题。

服务介绍

  1. redis

队列作用

  1. django web

web 页面管理

  1. celery

任务异步处理

Dockerfile

FROM centos:7.2.1511

MAINTAINER [email protected]

# yum 依赖
RUN yum -y install wget gcc automake autoconf libtool make openssl openssl-devel libffi-devel zlib*

# python3.8.1 环境搭建
RUN cd /opt/ \
	&& wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz \
	&& tar -zxvf Python-3.8.1.tgz \
	&& cd /opt/Python-3.8.1/ \
    && ./configure --with-ssl --prefix=/usr/local/python3 \
    && make && make install \
    && ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3 \
    && ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3

# 代码加入
ADD ./ /code
WORKDIR /code
COPY requirements.txt ./

# pip install
RUN pip3 install -r requirements.txt

RUN ln -s /usr/local/python3/bin/celery /usr/bin/celery

docker-compose

version: "3"
services:
  base:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
    - .:/code
  redis:
    image: redis
    ports:
    - "6379:6379"
    container_name: test_redis
  web:
    image: test_base
    ports:
    - "64000:64000"
    command: ["python3", "manage.py", "runserver", "0.0.0.0:64000"]
    depends_on:
      - base
    container_name: test_web
  celery:
    image: test_base
    command: ["celery", "-A", "walmart_bby", "worker", "-l", "info"]
    depends_on:
      - base
    container_name: test_celery

build

docker-compose -f docker-compose.yml up

容器如何访问宿主机

windows

docker.for.win.host.internal

mac

docker.for.mac.host.internal

other

ifconfig 查看docker0

或者采用link

你可能感兴趣的:(python,docker,运维)