{"id":248,"date":"2020-12-01T05:31:12","date_gmt":"2020-12-01T05:31:12","guid":{"rendered":"http:\/\/localhost\/anviam-blog\/?p=248"},"modified":"2024-09-26T04:27:09","modified_gmt":"2024-09-26T04:27:09","slug":"how-to-install-postgresql-on-docker","status":"publish","type":"post","link":"https:\/\/anviam.com\/blog\/how-to-install-postgresql-on-docker\/","title":{"rendered":"How To Install PostgreSQL on Docker"},"content":{"rendered":"\r\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-252\" src=\"https:\/\/anviam.com\/blog\/wp-content\/uploads\/2024\/09\/docker_postgres.png\" alt=\"\" \/><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">About Docker<\/h2>\r\n\r\n\r\n\r\n<p>Docker is a open source solution that is based container management service. The main purpose of docker is to increase the productivity of developers and dev-ops with less error pron. Docker provides a robust client server app architecture with a strong server, REST API and command line interface client. We can follow the same steps to run more containers and utilize fewer resources.<\/p>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\">Docker installation on ubuntu<\/h4>\r\n\r\n\r\n\r\n<p><strong>Open a terminal window and type to update repositories:-<\/strong><br \/><code>&gt; sudo apt-get update<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>Uninstall Old Versions of Docker if exist:-<\/strong><br \/><code>&gt; sudo apt-get remove docker docker-engine docker.io<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>To install Docker on Ubuntu, please follow:-<\/strong><br \/><code>&gt; sudo apt install docker.io<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>Start and Automate Docker:-<\/strong><br \/>&gt; sudo systemctl start docker<br \/><code>&gt; sudo systemctl enable docker<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>Check docker version:-<\/strong><br \/><code>&gt; docker --version<\/code><\/p>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\">Setup Postgres Image and container:-<\/h4>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-254\" src=\"https:\/\/anviam.com\/blog\/wp-content\/uploads\/2024\/09\/postgres-Docker-Hub.png\" alt=\"\" \/><\/figure>\r\n\r\n\r\n\r\n<p><strong>Firstly we need to pull postgres image on our local machine from docker hub. To do that simply we need to run this command<\/strong>:-<br \/><code>&gt; docker pull postgres<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>To check all exist docker images:-<\/strong><br \/><code>&gt; docker images<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>Start postgres instance:-<\/strong><br \/><code>&gt; docker run --name postgres-0 -e POSTGRES_PASSWORD=mypassword -p 5433:5433 -d postgres<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>Now we can check docker all running container by this command:-<\/strong><br \/><code>&gt; docker ps<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>Connect and run queries:-<\/strong><br \/><code>&gt; docker exec -it postgres-0 psql -U postgres<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>Create database:-<\/strong><br \/><code>&gt; CREATE DATABASE ps_database_1<\/code><br \/><strong>Connect with database:-<\/strong><br \/><code>&gt; \/c ps_database_1<\/code><br \/><strong>Create table:-<\/strong><br \/><code>&gt; CREATE TABLE table_1(something int);<\/code><br \/><code>&gt; INSERT INTO table_1 (something) VALUES (1);<\/code><\/p>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\">Some useful commands for docker<\/h4>\r\n\r\n\r\n\r\n<p><strong>To check docker version:-<\/strong><br \/><code>&gt; docker --version<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>To download docker image:-<\/strong><br \/><code>&gt; docker pull image_name<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>To list of all exist images on your machine:-<\/strong><br \/><code>&gt; docker images<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>To run docker image:-<\/strong><br \/><code>&gt; docker run -it -d image_name<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>To check what is running in docker:-<\/strong><br \/><code>&gt; docker ps<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>To list all docker running \/exist\/stopped with container info:-<\/strong><br \/><code>&gt; docker ps -a<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>To access docker container:-<\/strong><br \/><code>&gt; docker exec -it container_id bash<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>To remove docker container:-<\/strong><br \/><code>&gt; docker rm container_id<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>To remove image:-<\/strong><br \/><code>&gt; docker rmi image_id<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>To restart docker:-<\/strong><br \/><code>&gt; docker restart container_id<\/code><\/p>\r\n\r\n\r\n\r\n<p><strong>To stop docker container:-<\/strong><br \/><code>&gt; docker stop container_id<\/code><\/p>\r\n\r\n\r\n\r\n<p>&nbsp;<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>About Docker Docker is a open source solution that is based container management service. The main purpose of docker is to increase the productivity of developers and dev-ops with less error pron. Docker provides a robust client server app architecture with a strong server, REST API and command line interface client. We can follow the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1983,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4,6],"tags":[8],"class_list":["post-248","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-anviam","category-knowledge","category-technical","tag-docker-postgree-postgresql"],"rttpg_featured_image_url":{"full":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2024\/09\/docker_postgres.png",849,324,false],"landscape":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2024\/09\/docker_postgres.png",849,324,false],"portraits":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2024\/09\/docker_postgres.png",849,324,false],"thumbnail":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2024\/09\/docker_postgres-150x150.png",150,150,true],"medium":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2024\/09\/docker_postgres-300x114.png",300,114,true],"large":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2024\/09\/docker_postgres.png",800,305,false],"1536x1536":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2024\/09\/docker_postgres.png",849,324,false],"2048x2048":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2024\/09\/docker_postgres.png",849,324,false]},"rttpg_author":{"display_name":"Admin","author_link":"https:\/\/anviam.com\/blog\/author\/admin16anviam_root05\/"},"rttpg_comment":71,"rttpg_category":"<a href=\"https:\/\/anviam.com\/blog\/category\/anviam\/\" rel=\"category tag\">Anviam<\/a> <a href=\"https:\/\/anviam.com\/blog\/category\/knowledge\/\" rel=\"category tag\">Knowledge<\/a> <a href=\"https:\/\/anviam.com\/blog\/category\/technical\/\" rel=\"category tag\">Technical<\/a>","rttpg_excerpt":"About Docker Docker is a open source solution that is based container management service. The main purpose of docker is to increase the productivity of developers and dev-ops with less error pron. Docker provides a robust client server app architecture with a strong server, REST API and command line interface client. We can follow the&hellip;","_links":{"self":[{"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/posts\/248"}],"collection":[{"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/comments?post=248"}],"version-history":[{"count":2,"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/posts\/248\/revisions"}],"predecessor-version":[{"id":1986,"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/posts\/248\/revisions\/1986"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/media\/1983"}],"wp:attachment":[{"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/media?parent=248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/categories?post=248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/tags?post=248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}