Docker

新建Dockerfile文件

FROM python:3.6.2
ENV PYTHONUNBUFFERED 1
RUN mkdir /Django3
WORKDIR /Django3
COPY . /Django3/
RUN pip install -r requirements.txt

新建docker-compose.yml文件

version: '3.5'
services:

    db:
      container_name: 'postgres'
      image: postgres
      environment:
        POSTGRES_PASSWORD: password123
      ports:
        - "5432:5432"
        # (HOST:CONTAINER)
      volumes:
        - pgdata:/var/lib/postgresql/data/

    web:
      build: .
      command: python manage.py runserver 0.0.0.0:8000
      restart: always
      volumes:
        - api_data:/Django3
        # (HOST:CONTAINER) 绝对位置
      ports:
        - "8000:8000"
        # (HOST:CONTAINER)
      depends_on:
        - db

volumes:
    api_data:
    pgdata:

在命令行页面,切换到当前目录下,执行

docker-compose up

浏览器上输入: http:127.0.0.1:8000 即可访问

 

 原项目地址:github

 

Github上Docker 学习推荐

推荐学习1 ,推荐学习2

 

posted @ 2020-05-24 17:36  TY520  阅读(25510)  评论(0编辑  收藏  举报