当前位置: 代码迷 >> 综合 >> docker系列:Dockerfile 与 docker-compose应用
  详细解决方案

docker系列:Dockerfile 与 docker-compose应用

热度:97   发布时间:2023-10-29 19:28:39.0

Dockerfile 与 docker-compose应用

介绍

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

服务介绍

  1. redis

队列作用

  1. django web

web 页面管理

  1. celery

任务异步处理

Dockerfile

FROM centos:7.2.1511MAINTAINER 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.txtRUN ln -s /usr/local/python3/bin/celery /usr/bin/celery

docker-compose

version: "3"
services:base:build:context: .dockerfile: Dockerfilevolumes:- .:/coderedis:image: redisports:- "6379:6379"container_name: test_redisweb:image: test_baseports:- "64000:64000"command: ["python3", "manage.py", "runserver", "0.0.0.0:64000"]depends_on:- basecontainer_name: test_webcelery:image: test_basecommand: ["celery", "-A", "walmart_bby", "worker", "-l", "info"]depends_on:- basecontainer_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

  相关解决方案