If you are looking for a fast, easy and convenient way to run PostgreSQL and be able to access it via command line or SQL client - this is the perfect solution!
To start, make sure you have docker installed and that it is running on your machine. To do this run the following command in the command line:
docker -v
Next, you need to pull down the postgres image from docker hub. You can find the official postgres image here, if you need to run a specific version of postgres make sure to checkout the available tags.
docker pull postgres
if you are using a tag run the following command with the tag.
docker pull postgres:tag
Finally, we need to actually run the container. To do this, we need to pass a few flags in our next command.
docker run --name postgres-example -d -p 2022:5432 -e POSTGRES_PASSWORD=postgres postgres
- name will be the name of the container
- -d specifies that we want to run the container in detached mode
- -p specifies what local port we want mapped to our exposed container port
- -e provides the password environment variable to our container
- postgres is the name of the image we want to run
After this, you should be able to run a docker ps command to see the container running, or head over to your docker desktop application to interact with it there.
Now you can add this connection to your local sql client or use the CLI for your container to interact with postgres using psql.
Check out my video guide for more details
Top comments (0)