Postgres app not showing databases12/27/2022 ![]() ![]() ![]() To list the databases we can run \l inside the psql CLI to list the databases and see the Postgres database as seen below:Īs seen in the above picture \q will quit the psql CLI and exit the container’s shell we have ran exit. docker exec -it basic-postgres /bin/shĪfter we are inside the container we can run psql -username postgres to access the Postgres CLI. The container is running and ready to accept connections, if we run the following command we can go inside the container and run the psql command to see the postgres database which is the same as the username supplied in the event variable. When we run the command we will see an output like the below: The last parameter to the command is -it to have the tty available. Next, we use the -p parameter to map the host port 5432 to the container port 5432. The last 3 parameters are interesting, -v adds a volume to store data, for this example, it has been mapped to /tmp so all data will be lost when the machine restarts. Some environment variables have been added to make things easier. It tries to run a container from the posgres:14.1-alpine image which will be pulled in from Dockerhub by default if it does not exist.įirst, the name basic-posgres is given to the running container, and -rm will clean up the container and remove the file system when the container exits. Let’s evaluate what the above command does. To simply run the container using the Postgres 14.1 alpine image we can execute the following command: docker run -name basic-postgres -rm -e POSTGRES_USER =postgres -e POSTGRES_PASSWORD =4y7sV96vA9wv46VR -e PGDATA =/var/lib/postgresql/data/pgdata -v /tmp:/var/lib/postgresql/data -p 5432:5432 -it postgres:14.1-alpine The default bullseye version of Postgres docker image is 130 MB whereas the alpine one for the same version is 78 MB which is a lot smaller. We will be using the latest version 14.1 of PostgreSQL. ![]() Postgres with Docker #įor this post, we will use the official Postgres docker alpine image from DockerHub. Given the prerequisites have been mentioned we can move forward to the next section where we will run some docker commands. ![]() We will use an existing application/API with Node.js and Postgres replacing a remote Postgres with a local one running with Docker and Docker compose, so it would be advisable to read the previous post about it.An intermediate understanding of how relational databases work, especially PostgreSQL would be highly beneficial.For this guide, we will use the docker-compose version 1.29.1 on a Mac. Any prior grasp on Docker compose would be useful but not necessary.For this tutorial, docker version 20.10.10 will be used in a Mac. Basic knowledge of Docker will be helpful like executing commands like docker run, execute, etc.Prerequisites #īefore we dive into some CLI commands and a bit of code below are some prerequisites best to have: In the following section, we will look into some good to have things before diving into the commands to run Postgres with Docker. You can read more about this on why to use docker. When a new team member joins, the new member can get started in hours, it does not take days to be productive.Generally with docker if it runs on your machine it will run for your friend, on a staging environment and production environment given the version compatibility is maintained.Using multiple versions of PostgreSQL as per project or any other need is very easy.There are many good reasons to use any database like Postgres with Docker for local development, below are some good reasons: Why use Postgres with docker for local development # Adding Postgres with Docker to an existing Node.js project.Why use Postgres with docker for local development.In this post, we will look into how to run and use Postgres with Docker and Docker compose step-by-step keeping things simple and easy. Running Postgres with Docker and docker-compose makes it very easy to run and maintain especially in a development environment. This official feature matrix shows the wealth of features Postgres has. Postgres (a.k.a PostgreSQL) is an open-source, standards-compliant, and object-relational database been developed for more than 30 years now. Docker has shot up in popularity over the years. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |