You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Cormac Smartt 0a90483c18 Update 4 years ago
database Initial Commit 4 years ago
sql_files Initial Commit 4 years ago
Dockerfile Initial Commit 4 years ago Update 4 years ago
docker-compose.yml Initial Commit 4 years ago

A Simple Docker MySQL & Django setup


  • docker-compose >= 3
  • docker
  • MySQL >= 5.7



  • db_data:/var/lib/mysql

    • This maps the Docker volume created for this container to /var/lib/mysql/, where MySQL stores its data by default.
    • You don’t need to worry about this one!
  • ./database/schema.sql:/docker-entrypoint-initdb.d/schema.sql:ro

    • This maps ./database/schema.sql on your machine to an entrypoint, meaning your schema.sql will be loaded on the first run of the container.
    • This one is only used the first time you start your MySQL container.
  • ./sql_files/:/var/lib/mysql-files/

    • This maps ./sql_files/ on your machine to another directory in the container. This is important, as MySQL will only read data files from /var/lib/mysql-files, for security reasons.
    • This is where you’ll put any data that MySQL will need access to.


Working with this repository

  • Clone the repository to your local machine:

    • git clone && cd sql-docker
  • Pull new changes from the repo:

    • git pull
  • Push your changes to the repo:

    • git push

Working with Docker

  • Starting the MySQL Container:

    • docker-compose up -d db
      This starts only the container referred to by the ‘db’ section in your docker-compose.yml.
  • Stopping the MySQL Container:

    • docker-compose down
  • Removing the MySQL Volume (To start with a new schema, or if the docker-compose has changed majorly)

    • docker volume rm sqldocker_db_data
    • CAUTION: This will remove the contents of your database.
  • View all running containers:

    • docker ps

Interacting with MySQL

  • Connecting to your MySQL container:

    • mysql -udjango -p -h
    • You will be prompted for your password.
  • Reading in data from a file:

    • Be sure to put your files in ./sql_files/ and use the path /var/lib/mysql-files/filename path in your SQL commands.

Django with MySQL