Docker環境にGitHubリポジトリをクローンして開発する


press
Docker環境にGitHubリポジトリをクローンして開発する

Docker環境にGitHubリポジトリをクローンして開発する

Djangoを含んで起動させるDockerプロジェクトの例はいくつか見つかりましたが、Docker環境に別で開発しているリポジトリをクローンして開発を進める方法の情報が少なかったので方法をまとめました。

コードはGitHubリポジトリにあげています。

開発環境

$ tree
.
├── Dockerfile
├── README.md
├── docker-compose.yml
├── nginx
│   ├── Dockerfile
│   └── nginx.conf
└── simple-django-project
    ├── Pipfile
    ├── Pipfile.lock
    ├── README.md
    └── config

開発環境

PC: MacBook Pro (14, 2021)
OS: macOS Monterey 12.6.7
Python: 3.11.6

$ git clone https://github.com/nobnov/simple-django-project.git

Dockerfileを編集

    ADD PROJECTNAME/Pipfile /code/
    ADD PROJECTNAME/Pipfile.lock /code/
    ↓
    ADD simple-django-project/Pipfile /code/
    ADD simple-django-project/Pipfile.lock /code/

docker-compose.ymlを編集

    web:
    ...
    command: gunicorn WSGIPATH.wsgi:application --bind 0.0.0.0:8000
    volumes:
        - ./PROJECTNAME:/code
    ↓
    command: gunicorn config.wsgi:application --bind 0.0.0.0:8000
    volumes:
        - ./simple-django-project/config/:/code


    nginx:pw
    ...
    volumes:
            - ./PROJECTNAME/static:/static
    ↓
    volumes:
            - ./simple-django-project/config/static:/static

Dockerをビルド

$ docker-compose build

Dockerを起動

$ docker-compose up -d

コンテナ内にアクセス

$ docker-compose exec web bash

人気のタグ

Alembic API argparse Beautiful Soup black Channels charset CodeCommit datetime Django REST framework Docker enumerate f-string git GitHub glob Google Colaboratory i18n IAM Internship Jupyter Lambda Matplotlib Nginx OpenCV pandas PIL Pillow PostgreSQL PyCharm PyCon pyenv PyTorch Redis Rembg ReportLab requests S3 Sentry slack tqdm uWSGI venv Vue.js youtube


株式会社ファントムへのお問い合わせ

群馬県でPythonを使ったAIやソフトウェアを開発している株式会社ファントムが運営しています。




    Show Comments (0)

    Comments

    Related Articles

    Django

    pandasで読み込んだCSVの値がNaNだったときの対処方法

    DjangoのWEBプリケーションでCSVをpandasで読み込んでforで一行ずつループ処理をしたところ、毎回決まったところで決まったエラーが出たのでPyCharmのデバッグ機能を使って原因を調べた内容です。 プログラ […]

    Posted on by press
    Django

    DjangoとChannelsで簡単なチャットサーバーを構築(3)

    前回からの続きです。 チャンネルレイヤーを有効化 チャンネルレイヤーを使用するためにバックエンドにRedisを使用します。Redisを使用するためにDockerを起動します。 以下のコマンドを実行してRedisを起動しま […]

    Posted on by press