If you prefer using the PostgreSQL environment through a GUI, then follow along. You can list all the running databases and execute other SQL statements once connected through the command line utility. Next, you can start the PostgreSQL by running the following command on the same terminal.įigure 6 – Interacting with the PSQL command-line utility from terminal This command will start an interactive terminal inside the container. Now to connect to the database, let us open a new terminal window and type the following command. An important point to note here is that we have not executed the command in detached mode, which means the database or the container will be running as long as the terminal is open. Once you run the command, you can see that the container starts up and is ready to accept database connections. As you can see, there are two ports mentioned in the command which are in the form HOST_PORT:DOCKER_PORT.įinally, we provide the name of the docker image from which the container is to be created.įigure 5 – Running the PostgreSQL docker image Port – We need to define on which port is the database going to run in the container and which port on the host can be used to access it. Name – We need to provide a name for the container that is going to be created when docker will run the image.Įnvironment variables – When running the docker image for PostgreSQL, the only mandatory environment variable that we need to set is the password for the database. Along with that we also need to pass a few parameters as follows. In the above command, we call the run method on docker that will create a running instance of an existing docker image. To run the docker image for PostgreSQL, you can use the following command.ĭocker run –name pgsql-dev -e POSTGRES_PASSWORD=Welcome4$ -p 5432:5432 Postgres In other words, a container is a running instance of a Docker image. When we run a Docker image, a new container is created for that image. Now, that the image is installed, the next step would be to run this image. Once the docker image has been pulled to the local machine, you can check all installed images on your local by the following command.įigure 4 – Checking installed images on localĪs you can see in the above figure, the PostgreSQL image has been installed on your machine. To pull the image to your local, you can run the following command on the terminal.įigure 3 – Pulling the PostgreSQL Docker image on local The official PostgreSQL Docker image can be found on the Docker Hub. You can pull images from the Docker hub and can also publish your images to the Docker hub. Docker images are hosted on a repository on the cloud known as the Docker hub. Now, we are good to start pulling the PostgreSQL Docker image to our local machine. You can remove your existing images by using the following command on the terminal. It is important to note that there should be no active installation of the PostgreSQL Docker image or else you need to remove it before proceeding further. You can check all the images that are installed on the Docker by using the following command.įigure 2 – List all installed Docker Images Once Docker has been successfully installed, you can check it on the terminal by using the following command. Please refer to the installation procedure and follow along. In my previous article, How to set up and run SQL Server Docker image, I have talked about installing Docker on a local machine. During deployment, you need to just run the docker image on the production environment, and all the configurations will be in from the image. You can bundle your applications into docker images that will already store the necessary configurations required to run the application. In addition to PostgreSQL, we will also install PgAmin4 using Docker, which can be used to administer the PostgreSQL instance with Docker.ĭocker is an open-source containerized application technology using which you can deploy your applications easily on-premises or on the cloud. This article will introduce you to the basic concepts of installing and using Docker on a Mac and then pulling a PostgreSQL Docker image from the Docker Hub repository. With the rise in containerization technologies, PostgreSQL can now also be installed using Docker.ĭocker is a popular application that enables users to bundle applications into containers that help in the easy deployment of resources. PostgreSQL can be installed on any operating system like Windows, macOS, and Linux. It is highly stable and has a large community that maintains and supports the database development lifecycle. PostgreSQL is one of the most popular open-source databases that is being used by a lot of developers. In this article, we will learn how to get started using PostgreSQL on Docker.
0 Comments
Leave a Reply. |