• Skip to main content
  • Skip to primary sidebar

Code Inherit

Simple Programming Code Examples

Archives for July 2023

Import/Export Db from/to docker container Postgres

26th July 2023 by Site Admin Leave a Comment

How to take Postgres backup from container machine

/usr/bin/docker exec -it burkina-cluster-2363_db_1 pg_dump -h localhost -U dhis dhis2 | gzip> ~/dhis2_burkina_$(date “+%b_%d_%Y_%H_%M_%S”).pgsql.gz

get into container using exec command
docker exec -it burkina-cluster-2363_db_1 /bin/sh

take postgres database backup to current directory

pg_dump -h localhost -U dhis dhis2 | gzip> dhis2_burkina_09_Mar_2023.pgsql.gz
exit

copy postgres backup from container root to host machine
sudo docker cp burkina-cluster-2363_db_1:/dhis2_burkina_09_Mar_2023.pgsql.gz ~
OR
docker cp burkina-cluster-2363_db_1:/dhis2_burkina_09_Mar_2023.pgsql C:\Users\AnwarHossain\Downloads

sudo gzip dhis2_burkina_09_Mar_2023.pgsql

============================================
How to import Postgres backup from container machine

get into container using exec command
docker exec -it burkina-cluster-2363_db_1 /bin/sh

login to postgres dhis2 database
psql -h localhost -p 5432 -U dhis -W dhis2

SELECT ‘drop table if exists “‘ || tablename || ‘” cascade;’
FROM pg_tables
where schemaname = ‘public’;

drop all existing tables using above query output

exit from postgres
\q

copy postgres backup from host machine to container root
docker cp C:\Users\AnwarHossain\Downloads\dhis2_burkina_09_Mar_2023.pgsql burkina-cluster-2363_db_1:/
docker cp ~/dhis2_burkina_09_Mar_2023.pgsql burkina-cluster-2363_db_1:/

get into container using exec command
docker exec -it burkina-cluster-2363_db_1 /bin/sh

importing postgres backup to postgres container from current directory
psql -U dhis dhis2 < dhis2_burkina_09_Mar_2023.pgsql

docker restart burkina-cluster-2363_core_1

=================================================

docker stop $(docker ps -aq) // stop all container
docker container rm $(docker container ls -aq) // remove all containers
docker rmi $(docker images -q) // remove all images
docker volume prune // remove all stopped container volumes
docker network prune // remove all stopped container networks

docker system prune -a
– all stopped containers
– all networks not used by at least one container
– all images without at least one container associated to them
– all build cache

# Stop services only
docker-compose stop
# Stop and remove containers, networks..
docker-compose down
# Down and remove volumes
docker-compose down –volumes
# Down and remove images
docker-compose down –rmi <all|local>

Filed Under: dhis2

How to delete dhis2 Standard Apps from Docker Linux Container

26th July 2023 by Site Admin Leave a Comment

  1. docker exec -it burkina2-2363_core_1 /bin/sh
  2. cd /DHIS2_home/files/apps
  3. ls -l
  4. rm -rf dhis2-Burkina-NetSIGL-2-2.1

Filed Under: dhis2

Primary Sidebar

Recent Posts

  • Bijoy Converter
  • How to amend previous commit with current changes in git and github?
  • How to install PHP 8.1 alongside PHP 7.4 using HomeBrew in MacOs?
  • Create a shell script to switch 7.4 to 8.1 and vice versa
  • How to reflect PHP8.1 to Apache in MacOS?

Recent Comments

    Archives

    • October 2025
    • September 2024
    • January 2024
    • July 2023
    • October 2021
    • September 2021
    • February 2021
    • January 2021
    • October 2020
    • September 2020
    • August 2020
    • May 2020
    • March 2020
    • February 2020
    • January 2020
    • November 2019
    • May 2019

    Categories

    • Couchbase
    • Cron Job
    • dhis2
    • Linux, MySQL
    • MySQL
    • Oracle
    • Oracle Client
    • PHP
    • SSL
    • Subdomain
    • Uncategorised
    • Wordpress
    • WP
    • Zip

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org

    Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in