Skip to content

Latest commit

 

History

History
84 lines (54 loc) · 1.46 KB

create-docker-image.md

File metadata and controls

84 lines (54 loc) · 1.46 KB

Create a postgres docker image

Create a postgres docker image with user 'student' password 'student'.

Files to build image

Create Dockerfile

FROM postgres
ENV POSTGRES_PASSWORD postgres 
COPY init.sql /docker-entrypoint-initdb.d/

Create init.sql file

DROP DATABASE IF EXISTS studentdb;
CREATE DATABASE studentdb;

CREATE USER student
WITH SUPERUSER PASSWORD 'student';

GRANT ALL PRIVILEGES ON DATABASE studentdb TO student;

To build from Dockerfile and init.sql and run from local build image

docker build -t postgres-student-image .

docker run -d --name postgres-student-container -p 5432:5432 postgres-student-image

Build and push image to docker hub

Login

docker login docker.io

Build image and tag with docker username for relative path

docker build -t postgres-student-image .
docker tag postgres-student-image onekenken/postgres-student-image
docker login docker.io
docker push onekenken/postgres-student-image

Pull and run from docker hub retrieved image

docker pull onekenken/postgres-student-image

docker run -d --name postgres-student-container -p 5432:5432 onekenken/

postgres-student-image

Image at docker hub address.


To rinse and repeat

docker stop postgres-student-container
docker rm postgres-student-container
docker rmi postgres-student-image