码迷,mamicode.com
首页 > 数据库 > 详细

[DevOps] Set up and run a PostgreSQL instance locally with Docker Compose

时间:2020-05-18 19:12:00      阅读:67      评论:0      收藏:0      [点我收藏+]

标签:sage   project   learn   volumes   ESS   lex   The   DBName   instance   

When we need to spin up a database instance for our new project, installing the database management system directly on our local machine is almost always a bad idea. Luckily, Docker is here to help us practically reduce the complexity of dealing with "missing dependencies" and weird error messages down to zero.

In this lesson, we will learn how to get a PostgreSQL instance running locally with Docker Compose, so we can work on the database integration of our project and test things out with ease. To follow this lesson, you will need to have Docker pre-installed.

 

docker-compose.yml:

version: "3.8"
services:
  db:
    image: "postgres:12"
    ports:
      - "54320:5432"
    volumes:
      - ./pgdata:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=alice
      - POSTGRES_PASSWORD=wonderland
      - POSTGRES_DB=myawesomedb

 

 

# Up and Running

docker-compose -d

# Check Whether contain is running

docker-compose ps

# enter the shell

docker-compose run db bash

## Verify db exist

poql --host=db --username=alice --dbname=myawesomedb

## Esc the db

Ctrl + d twice

# Off

docker-compose down

 

[DevOps] Set up and run a PostgreSQL instance locally with Docker Compose

标签:sage   project   learn   volumes   ESS   lex   The   DBName   instance   

原文地址:https://www.cnblogs.com/Answer1215/p/12912149.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!