Skip to content

Commit e0ca89a

Browse files
author
malcata
committed
first version
1 parent 1c2bec5 commit e0ca89a

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Dev decision to use latest. Could instead lock a python version e.g. :3.6, :2.7
2+
FROM python:latest
3+
4+
MAINTAINER Malcata https://github.com/malcata
5+
6+
## Install Django
7+
RUN pip install --no-cache-dir Django psycopg2 mysqlclient
8+
9+
## Install all db options, minimal footprint
10+
RUN apt-get update \
11+
&& apt-get install -y --no-install-recommends \
12+
gcc \
13+
gettext \
14+
mysql-client libmysqlclient-dev \
15+
postgresql-client libpq-dev \
16+
sqlite3 \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
20+
### Eventual TEST Environment
21+
## At build time copy everything directly from the continuous integration
22+
#RUN mkdir -p /usr/src/app
23+
#WORKDIR /usr/src/app
24+
#COPY requirements.txt ./
25+
#RUN pip install --no-cache-dir -r requirements.txt
26+
#COPY . .
27+
28+
### DEV ENVIRONMENT
29+
## At run time mount the code folder
30+
31+
EXPOSE 8000
32+
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export IMAGE_NAME?=malcata/django
2+
export CONTAINER_NAME?=django
3+
export SOURCE_DIR?=~/source/project
4+
export WORK_DIR?=/usr/src/app
5+
6+
build:
7+
docker build -t ${IMAGE_NAME} -f Dockerfile .
8+
9+
run:
10+
docker run --name ${CONTAINER_NAME} \
11+
--volume ${SOURCE_DIR}:${WORK_DIR} \
12+
--workdir ${WORK_DIR} \
13+
--publish 8000:8000 \
14+
--detach ${IMAGE_NAME}
15+
16+
rmi:
17+
docker rmi -f $(IMAGE_NAME)
18+
19+
clean:
20+
-docker rm -v $$(docker ps -a -q -f status=exited)
21+
-docker rmi $$(docker images -q -f dangling=true)
22+
-docker rmi $(IMAGE_NAME)
23+
-docker rmi python
24+

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
11
# docker-django
22
A dockerfile to run django
3+
4+
## Why
5+
The [official docker image for django](https://hub.docker.com/_/django/) is deprecated since 31 Dec 2016. Even those did not seem development friendly since generated images with a copied version of the project instead of a mounted project.
6+
7+
## How to install
8+
9+
1. Install docker ;-)
10+
2. Clone repository:
11+
```shell
12+
https://github.com/malcata/docker-django.git
13+
```
14+
3. Configure required environment variables, eventually on a bash_profile file:
15+
```shell
16+
$ export SOURCE_DIR="<project source folder>"
17+
```
18+
4. Edit settings.py with your IP:
19+
````shell
20+
ALLOWED_HOSTS = ['x.x.x.x']
21+
```
22+
23+
## Usage
24+
25+
1. Generate the docker image
26+
```shell
27+
$ make build
28+
```
29+
2. Run the container
30+
```shell
31+
$ make run
32+
```
33+
3. Use browser to access django http://container-ip:8000
34+
35+
Check the [Makefile](Makefile) for further details.
36+
37+
38+
## Contributing
39+
40+
Please follow the Github flow process (branch, commits and pull request)...
41+
42+
43+
## License
44+
45+
The code in this repository, unless otherwise noted, is MIT licensed. See the `LICENSE` file in this repository.
46+

0 commit comments

Comments
 (0)