Giter VIP home page Giter VIP logo

g's Introduction

fastapi-mysql-docker

  • FastAPI
  • MySQL
  • Docker

Setup

Please install Docker and Docker compose first.

https://www.docker.com/

After installation, run the following command to create a local Docker container.

docker-compose build
docker-compose up -d

If you want to check the log while Docker container is running, then try to use following command:

docker-compose up

If Docker is running successfully, the API and DB server will be launched as shown in the following:

Be careful, it won't work if the port is occupied by another application.

If you want to check docker is actually working, then you can check it with following command:

docker ps

If you want to go inside of docker container, then try to use following command:

docker-compose exec mysql bash
docker-compose exec api bash

For shutdown of the docker instance, please use following command:

docker-compose down

Need a front-end app?

If you need a front-end app for this server-side & DB server.

You can clone the front-end template from:

Note

How to check the DB tables in container

You can check the DB data by actually executing a query using the following command:

docker-compose exec mysql bash
mysql -u root -p
mysql> USE fastapi_app;
mysql> SHOW TABLES;

How to add a library

You may want to add libraries such as requests, in which case follow these steps:

  • Add the library to requirements.txt

e.g., if you want to add requests:

requests==2.30.0

Then try a re-build and see.

docker-compose build
docker-compose up

Python library packages

Some of the Python packages used in this app are defined in api/requirements.txt. Also you can add other packages there.

Environment variable

Some of environment variable, like a database name and user is defined in docker-compose.yml. You can customize it as you like.

If you will use docker, then please define your environment variable to docker-compose.yml. However, you will NOT use docker, then please create .env file for your API server.

DB Migrations

When creating DB docker container, docker will create predefined tables in mysql/db folder. That help your team to control versions of database.

The sample table definition has already been created with the name create_user_table.sql.

Save the local DB changes as a dump file

docker-compose exec database mysqldump -u root -p fastapi_app > mysql/db/dump.sql

API documentation

http://localhost:8000/redoc

g's People

Contributors

galacticagent 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.