Skip to content

s-evsyukov/docker_postgres_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Postgres Pscopg2


Skills and tools:

Docker Docker-compose PostgreSQL Adminer Python Pscorpg2 DockerHUB


Task: Initiate Docker-compose container with PostgreSQL

  1. Pull and initiate Docker image with PostgreSQL
  2. Pull and initiate Docker image with Adminer
  3. Create Docker-compose configuration with next capability:
    • Database "Northwind" have to be initiated at start to PostgreSQL
    • Adminer can connect PostgreSQL and edit database inside docker container
    • PostgreSQL can be reached from host IP
    • Custom application have to run queri after database initialisation
  4. Run custom application with next task: Query how many units of products are on sale by product category in price equivalent. Show those that are more expensive than 5000
  5. Save image to DockerHub

Progress of work:

  1. Installing Docker infrastructure:

  2. Configure Docker access:

  • add docker to group
$ sudo groupadd docker 
  • add your user to the docker group:
$ sudo usermod -aG docker $USER
  • Check if docker belongs to your user group:
$ groups
docker adm cdrom sudo dip plugdev lpadmin lxd sambashare foo
  1. Creating custom application: to run database queri
  2. Using psycorpg2 database adapter to connect app to PostgreSQL database
  3. Configure import requirements for custom application
  4. Download Northwind database sample to ./db directory
  5. Creating Dockerfile to configure Docker image run steps
  6. Creating Docker-compose.yaml to configure Docker container infrastructure
    • setting Postgres configuration with initialisation.db values(Northwind will be initialised at startup of database)
    • setting Adminer configuration
    • setting Custom App configuration
    • Docker-compose will create default network to provide connection between application. We need to specify only ports to make application available from host.
  7. Building image and running container with docker-compose:
 $ docker-compose up --build
  1. Shutting down container:
$ docker-compose down --volumes
  1. Renaming image and adding version tag:
$ docker tag docker_postgres_app valknutt/docker_postgres_psycorpg2:v1.0
  1. Creating repository with name docker_postgres_psycorpg2 on DockerHUB

  2. login to DockerHUB from terminal:

$ docker login --username ******** --pasword *********
  1. Pushing image to DockerHUB:
$ docker push valknutt/docker_postgres_psycorpg2:v1.0
  1. Cleaning local Docker containers
$ docker container prune
  1. Cleaning local Docker images
$ docker images prune
  1. Delete unused images if needed
$ docker images
$ docker rmi image_id 

About

docker postgresql practice

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published