Code Monkey home page Code Monkey logo

docker-postgresql's Introduction

PostgreSQL 9.6 Dockerfile on CentOS 7

This repository contains a Dockerfile to build a Docker Image for PostgreSQL on CentOS 7

Base Docker Image

Usage

Installation

  1. Install Docker.

build from Github

To create an image, clone this repository and execute the following command on the docker-postgresql folder:

docker build -t myname/postgresql:latest .

Another alternatively, you can build an image directly from Github:

docker build -t="myname/postgresql:latest" github.com/edib/docker-postgresql

Create and running a container

Create container:

(Not recommended for production use)

docker create -it -p 5432:5432 --name mypg96 myname/postgresql

Start container:

docker start postgresql96

Another way to start a postgresql container:

docker run -d -p 5432:5432 --name mypg96 myname/postgresql

Connection methods:

PostgreSQL client:

docker exec -it mypg96 psql

Bash:

docker exec -it mypg96 bash

Creating a database and username

You can create a postgresql database and superuser at launch. Use DB_NAME, DB_USER and DB_PASS variables.

docker create -it -p 5432:5432 --name mypg96 --env 'DB_USER=YOUR_USERNAME' --env 'DB_PASS=YOUR_PASSWORD' --env 'DB_NAME=YOUR_DATABASE' myname/postgresql

If you don't set DB_PASS variable, an automatic password is generated for the PostgreSQL database user. Check to stdout/stderr log of container created:

docker run -d -p 5432:5432 --name mypg96 --env 'DB_USER=YOUR_USERNAME' --env 'DB_NAME=YOUR_DATABASE' myname/postgresql
docker logs mypg96

The output:

...
WARNING: 
No password specified for "YOUR_USERNAME". Generating one
Password for "YOUR_USERNAME" created as: "aich3aaH0yiu"
...

To connect to newly created postgresql container:

docker exec -it mypg96 psql -U YOUR_USERNAME

Another way to connect to postgresql container with your newly created user:

psql -U YOUR_USERNAME -h $(docker inspect --format {{.NetworkSettings.IPAddress}} postgresql94)

Upgrading

Stop the currently running image:

docker stop mypg96

docker-postgresql's People

Watchers

 avatar

Forkers

samilekesiz

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.