Dockerfile 与 docker-compose应用
介绍
搭建小工具使用时,python3.8.1在centos8各种错误,习惯了centos7, 真是折磨人,于是就用docker构建,解决环境的问题。
服务介绍
- redis
队列作用
- django web
web 页面管理
- celery
任务异步处理
Dockerfile
FROM centos:7.2.1511
MAINTAINER sofarsofunny@Gmail.com
# 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
版权声明:本文为qq_36800514原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。