Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Add Docker support and update the readme file.
Browse files Browse the repository at this point in the history
  • Loading branch information
b4oshany committed Jul 13, 2019
1 parent 2363ab0 commit 355be19
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ ENV/

# SQLite3
db.sqlite3


# Merge backup files
*.orig
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# The first instruction is what image we want to base our container on
# We Use an official Python runtime as a parent image
FROM python:3.5.7

# The enviroment variable ensures that the python output is set straight
# to the terminal with out buffering it first
ENV PYTHONUNBUFFERED 1

# Get the Real World example app
COPY . /drf_src

# Set the working directory to /drf
# NOTE: all the directives that follow in the Dockerfile will be executed in
# that directory.
WORKDIR /drf_src

# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt

VOLUME /drf_src

EXPOSE 8000

CMD python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This repo is functionality complete — PR's and issues welcome!

## Installation

### Option 1: Install from source

1. Clone this repository: `git clone [email protected]:gothinkster/productionready-django-api.git`.
2. `cd` into `conduit-django`: `cd productionready-django-api`.
3. Install [pyenv](https://github.com/yyuu/pyenv#installation).
Expand All @@ -22,3 +24,62 @@ If all went well then your command line prompt should now start with `(productio
If your command line prompt does not start with `(productionready)` at this point, try running `pyenv activate productionready` or `cd ../productionready-django-api`.

If pyenv is still not working, visit us in the Thinkster Slack channel so we can help you out.

#### Setting up the Database

```bash
python manage.py makemigrations
python manage.py migrate
```

#### Running the DJango App
```
python manage.py runserver 0.0.0.0:8000
```

#### Adding an admin user
However, there aren’t any users for our Django DRF application.
In order to create admin user, we need to access our container to run the createuser command then enter the promoted credentials:
```bash
python manage.py createsuperuser
```


### Option 2: Use Docker

If you don't have yet a running docker installation, install first docker with

```bash
sudo apt-get install docker.io
```

Fetch the repository from docker
```bash
docker pull realworldio/django-drf
```

#### Running the DJango App
Create a folder to mount the source code of the app
```bash
mkdir ~/django_drf_project
```

Run the DJango DRF app via Docker container
```bash
docker run -d -p 8080:8000 -v ~/django_drf_project:/drf_src --name django_drf_app realworldio/django-drf
```

#### Adding an admin user
However, there aren’t any users for our Django DRF application.
In order to create admin user, we need to access our container to run the createuser command:
```bash
docker exec -it django_drf_app /bin/bash
```

To add an admin user, you need to run the following code in your container then enter the promoted credentials:
```bash
python manage.py createsuperuser
```

Afterwards, exit the Docker container running the `exit` command.

0 comments on commit 355be19

Please sign in to comment.