English | 한국어
This is a repository to demonstrate how to develop a full-stack web application using Docker.
You can simply run the application with Docker and Docker Compose.
The application implemented is a todo app like a Microsoft To Do.
-
Back-end: Django - Django REST Framework (Created using
django-admin startproject backend) -
Front-end: React - Create-React-App (Created using
npx create-react-app frontend) -
Database: PostgreSQL
-
Clone the repository using this command.
$ git clone --recursive https://github.com/litsynp/docker-example.git
- If you missed
--recursiveoption, fetch the frontend submodule usinggit clone.
- If you missed
-
Put all the python modules in
requirements.txt. -
Run
yarninfrontenddirectory to fetch yarn modules.$ cd frontend $ yarn -
Run
docker compose up --buildin the root directory. You will create front-end, back-end and database Docker containers. -
When the docker containers are all up and running, open another terminal and run
docker-compose exec backend python manage.py migrateto proceed with data migration. If you skip this, you will encounter an error in Django backend container later, because the DB has not been initialized.
-
docker compose downfor just stopping the server.- If you want to run the server again after stopping it, run
docker compose upagain.
- If you want to run the server again after stopping it, run
-
docker compose down -vto stop and remove the server. This will remove all the volumes of the containers.- If you want to run the server again after stopping and removing it, run
docker compose up --build. Build only when you are running the server for the first time.
- If you want to run the server again after stopping and removing it, run
-
The production build
prodincludes NGINX as a load balancer. -
To run as production build, append
-f docker-compose.prod.ymlafterdocker composefor all the commands above.- e.g.,
docker compose -f docker-compose.prod.yml up
- e.g.,
-
You can include
.vscode, which includes workspace settings for Visual Studio Code, to.gitignoreas well. It is included as an example here.
.env files are for keeping secrets and credentials that should not be exposed to Git repository.
You must inlcude them to .gitignore so that the Git repository doesn't include it.
- There are sample
.envfiles ofdevandprodbuild insettingsdirectory.
