• docker compose


    1

    I'm trying to create a docker environment for my django project

    my dockerfile :

     FROM python:3
     ENV PYTHONUNBUFFERED=1
     RUN apt-get install default-libmysqlclient-dev
     RUN mkdir /config  
     ADD /config/requirements.txt /config/  
     RUN pip install -r /config/requirements.txt
     RUN mkdir /src
     WORKDIR /src
    

    my docker-compose :

     version: '3'
    
    services:
       db:
         image: mysql
         environment:
           MYSQL_ROOT_PASSWORD: root
           MYSQL_USER: root
           MYSQL_PASSWORD: root
           MYSQL_DATABASE: ProjetDjango
         container_name: mysql01
         restart: always
       nginx:
         image: nginx:1.13-alpine
         container_name: nginx01
         ports:
           - "8000:8000"
         volumes:
           - ./project:/src
           - ./config/nginx:/etc/nginx/conf.d
         depends_on:
           - web
       web:
         build: .
         container_name: django01
         command: bash -c "python3 manage.py makemigrations && python3 manage.py migrate && python3 manage.py collectstatic --noinput && gunicorn hello_django.wsgi -b 0.0.0.0:8000"
         depends_on:
           - db
         volumes:
           - ./project:/src
         expose:
           - "8000"
         restart: always
    

    my settings.py :

    DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'ProjetDjango',
        'USER': 'root',
        'PASSWORD': 'root',
        'HOST': '127.0.0.1', 
        'PORT': '3306',
     }
    }
    

    I've got this error while running : docker-compose up

    When you link your db service to your web service in docker so you must use your db service name instead of your database server ip for connecting database :

    db:
        image: mysql
        restart: unless-stopped
        container_name: db_of_my_project
    
    web:
        build: .
        container_name: django01
        command: ...
        links:
            - db
        volumes:
            - ./project:/src
        expose:
            - "8000"
        restart: always
  • 相关阅读:
    k8s-istio记录
    k8s
    单词 -(动物)
    RxJs
    .netcore 3.1 unbuntu
    单词规整
    AutoMapper
    时间
    ye
    特殊权限
  • 原文地址:https://www.cnblogs.com/SunshineKimi/p/14924311.html
Copyright © 2020-2023  润新知