Coder Social home page Coder Social logo

docker-django-mysql's Introduction

Documentation

Instructions

This is a simple example how to use docker with django. You may change the database credentials, network name, container names and image names on docker-compose.yml how is convenient for you.

Create containers docker-compose

Create the container by using docker-compose

doocker-compose build web
docker-compose up -d

Create a new project

If you are starting from the scratch create new django project

docker exec django-web django-admin startproject mysite .

or if this doesn't work for you get inside the container and create the project from there

docker exec -it django-web bash
django-admin startproject mysite .

The project is going to be created within the app folder.

Permissions

If you are using linux and you don't have permission on you host in cases when you create a new app use the following command to make your user a owner:

sudo chown -R $USER:$USER .

Database settings

Change the database settings in your settings.py. For example:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'django-test',
        'USER': 'jethax',
        'PASSWORD': '1234',
        'HOST': 'django-mysql',
        'PORT': '3306',
    }
}

Migration

To run the migration login in the container:

docker exec -it django-web bash

After you are inside the container run the migration:

python manage.py migrate

Run server

Option 1

Use the following command to run the server (Enter the command from your host)

docker exec -it django-web python manage.py runserver 0.0.0.0:8000

Option 2

To run the server on container start on docker-composer.yml find the command:

command: tail -f /dev/null

and change it to:

command: python manage.py runserver 0.0.0.0:8000 

The first option is more preferable since usually you want to see the terminal errors.

docker-django-mysql's People

Contributors

jetmirhaxhisefa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.