1.Dockerfile制作镜像
| |
| FROM ubuntu:20.04 |
| |
| |
| RUN mkdir /APP |
| ADD . /APP |
| |
| RUN cat /APP/config/sources.list > /etc/apt/sources.list \ |
| |
| && apt-get -y update \ |
| |
| && apt-get install -y python3-dev python3-pip \ |
| && apt-get install -y python3-setuptools \ |
| && apt-get install -y libmysqlclient-dev \ |
| |
| && pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ \ |
| && pip install -r /APP/config/requirements.txt |
| |
| |
| |
| |
| |
| EXPOSE 80 8080 8000 3210 |
| |
| |
docker image build -t djangoproject:1.0 .
2.编写docker-compose.yml
采用docker-compose的部署方式,traefik会自动申请域名的SSL证书,并监听端口(此处端口就是容器内部端口,映射端口不需要了)。
| version: '3' |
| |
| services: |
| djangoproject: |
| image: bithao/djangoproject:1.0 |
| |
| volumes: |
| - ./django:/APP |
| deploy: |
| labels: |
| traefik.enable: "true" |
| traefik.http.services.djangoproject.loadbalancer.server.port: 8000 |
| traefik.http.routers.djangoproject-unsecure.rule: Host(`django.bitworkshop.cn`) |
| traefik.http.routers.djangoproject-unsecure.entrypoints: web |
| traefik.http.routers.djangoproject.rule: Host(`django.bitworkshop.cn`) |
| traefik.http.routers.djangoproject.entrypoints: websecure |
| traefik.http.routers.djangoproject.tls.certresolver: letsencrypt |
| networks: |
| - public-db |
| - http-servers |
| |
| working_dir: /APP |
| restart: always |
| command: /bin/bash /APP/config/start.sh |
| |
| |
| |
| networks: |
| public-db: |
| external: |
| name: db-net |
| http-servers: |
| external: |
| name: traefik |
| |
docker stack deploy -c docker-compose.yml djangoproject --with-registry-auth
Comments 1 条评论
顶🔝