-
Install Docker.
-
Start the Docker service:
sudo service docker start
-
Change to the
django/
directory:cd django/
-
Build the Docker image:
sudo docker build -t da8ah/django-angular-crud .
-
Run the Docker image without Detach mode (-d) nor Volume (-v) for simplicity:
sudo docker run -p 8000:8000 da8ah/django-angular-crud
sudo docker run -d -v ~/programming/django-angular-crud/django/:/app -p 8000:8000 da8ah/django-angular-crud
-
Test if it's running; it should return an array from the database:
sudo docker build -t <tag-name> <dockerfile-dir>
- Tag (-t): image alias
- Dockerfile directory: directory where the Dockerfile is
sudo docker run -d -v <project-dir>/:/app -p <host-port>:<container-port> <tag-name>
- Detached mode (-d): runs container in its own process so it doesn't close when the terminal is closed.
- Volume (-v): mount directory as a volume bind so changes made in the files of the given directory will update in the container.
- Ports (-p): the container port will be forwarded to the host port so you can use it in any browser like
http://localhost:<host-port>
. - Tag: tag of the image that must run.
These commands can be useful for manage images and containers.
-
Stop and remove container processes:
sudo docker stop <container-id>
sudo docker rm <container-id>
-
List all images and remove images:
sudo docker images sudo docker image rm <image-id>
Use the container id returned by the run command to operate with the container.
-
Open the container and Django server logs:
sudo docker logs --follow <container-id>
-
Access the container shell:
sudo docker exec -it <container-id> sh
-
Make Django migrations in the container shell if they are required:
python3 manage.py migrate python3 manage.py makemigrations <app-name>
-
Make sure Backend it's running.
-
Open the Angular project in another terminal:
cd angular/
-
Install packages:
npm i
-
Run the server:
ng serve -o
-
If your browser ensures https usage you may use incognito mode with http only.