![]() 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.
0 Comments
Leave a Reply. |