Docker - andreasdvorak/running_results GitHub Wiki
Tuturials
https://docs.docker.com/compose/
https://docs.docker.com/compose/django/
Postgres
https://hub.docker.com/_/postgres/
pip install psycopg2
python -m pip freeze > requirements.txt
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'hunter2',
'HOST': 'db'
}
}
After pip install
The COPY is only done, when the image is build. So after an installation of a pip module we need the build parameter.
run the following command, otherwise the new pip module is missing and you get an error
docker-compose up --build
Docker commands
Test docker
docker build .
Show all docker container that are running
docker ps
Show all docker container
docker ps -a
Show diff of file operations in an image
docker diff 921fd93e507d
Show log of a container
docker logs -t 8adb0bb101c1
docker logs -f 8adb0bb101c1
Stop a container
docker kill 8adb0bb101c1
docker stop 8adb0bb101c1
Show CPU of the container
docker stats
Remove container
docker rm 8adb0bb101c1
Clean up unused images
docker image prune
Clean up unused volumes
docker volume prune
Docker compose commands
run docker-compose
docker-compose up
docker-compose down
run docker-compose with a special yml file
docker-compose -f docker-compose-deploy.yml up [--build]
docker-compose exec web python manage.py makemigrations
docker-compose exec web python manage.py migrate
docker-compose exec web python manage.py createsuperuser
Open bash in container
docker exec it <container-name> bash
Show size of docker
docker system df
Inspect images
docker inspect <container-id>
Backup
Postgres
docker ps
docker exec <container id> /usr/bin/pg_dump -U postgres postgres > backup.sql
env files
docker cp <container id>:/app/.env env_1
docker cp <container id>:/app/running_results/.env env_2