Git Product home page Git Product logo

postgresql-docker-dockercompose's Introduction

PostgreSQL-Docker-DockerCompose

How to Install PostgreSQL Using Docker and Docker Compose ?

Installing PostgreSQL using Docker and Docker Compose is a straightforward process. Docker allows you to package an application and its dependencies into a container, making it easy to deploy and run consistently across different environments.

Here are the steps to install PostgreSQL using Docker and Docker Compose:

Step 1: Install Docker and Docker Compose

Ensure that Docker and Docker Compose are installed on your machine. You can download and install Docker from the official Docker website and Docker Compose from the Docker Compose GitHub releases page.

Step 2: Create a Docker Compose File

Create a file named docker-compose.yml in your project directory. This file will define the services, networks, and volumes for your PostgreSQL container.

# docker-compose.yml

version: '3'

services:
  postgres:
    image: postgres:latest
    restart: always
    environment:
      POSTGRES_DB: your_database_name
      POSTGRES_USER: your_username
      POSTGRES_PASSWORD: your_password
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  postgres_data:

Replace your_database_name, your_username, and your_password with the desired values for your PostgreSQL database.

Step 3: Start PostgreSQL Container

Open a terminal in your project directory and run the following command to start the PostgreSQL container:

docker-compose up -d

This command will pull the PostgreSQL image from Docker Hub, create a container based on the configuration in your docker-compose.yml file, and run it in the background (-d flag).

Step 4: Access PostgreSQL

You can now access your PostgreSQL database using a database client or command-line tools. The default PostgreSQL port is 5432.

  • Host: localhost or 127.0.0.1
  • Port: 5432
  • Username: The username you specified in the docker-compose.yml file
  • Password: The password you specified in the docker-compose.yml file
  • Database: The database name you specified in the docker-compose.yml file

Step 5: Stop and Remove the Container

When you're done working with PostgreSQL, you can stop and remove the container using the following command:

docker-compose down

This will stop and remove the PostgreSQL container, but the data will persist in the postgres_data volume defined in the docker-compose.yml file.

By following these steps, you can easily set up and run a PostgreSQL instance using Docker and Docker Compose.

postgresql-docker-dockercompose's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.