0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Docker】python(Flask)+GraphQL(graphene)+MySQL(sqlalchemy)の環境を構築する

Last updated at Posted at 2020-10-05

はじめに

pythonのwebフレームワークのFlaskを用いてGraphQL環境をdockerを用いて構築する。

ここでは、docker,docker-composeについて説明する。grapheneの設定はPython (Flask) with GraphQL Server implementing SQLAlchemy, graphene, and SQLite を参照

必要ファイル、ディレクトリ

.
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
├── books/ ← 上記のサイトを参照

ファイルの内容

requirements.txt

requirements.txt
Flask==1.1.2
Flask-GraphQL==2.0.1
graphene==2.1.8
graphene-sqlalchemy==2.3.0.dev1
SQLAlchemy==1.3.17
pymysql

Dockerfile

Dockerfile
FROM python:3.7-slim

WORKDIR /mnt

COPY requirements.txt ./

RUN pip install --no-cache-dir -r requirements.txt


docekr-compose.yml

docker-compose.yml
version: '2'
services:
  graphql: 
    build: .
    volumes: 
    - './:/mnt'
    ports:
        - "5000:5000"
    tty: true
  db:
    image: mysql:5.7
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_DATABASE: test
      MYSQL_ROOT_PASSWORD: test
      MYSQL_USER: test
      MYSQL_PASSWORD: test
    ports:
        - "3306:3306"

他のファイルはPython (Flask) with GraphQL Server implementing SQLAlchemy, graphene, and SQLiteを参照

実行

以下のコマンドを実行する

$ docker-compose up -d

http://localhost:5000/graphql にアクセス

以下の画面が表示されれば成功!

スクリーンショット 2020-10-05 23.37.17.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?