Skip to content

Instantly share code, notes, and snippets.

@DanielRamosAcosta
Created November 30, 2016 01:35
Show Gist options
  • Save DanielRamosAcosta/275dd58de66951612b9d2926be6d4197 to your computer and use it in GitHub Desktop.
Save DanielRamosAcosta/275dd58de66951612b9d2926be6d4197 to your computer and use it in GitHub Desktop.
Base de datos PostgreSQL junto con pgweb usando Docker
# docker-compose up
# Borrar todos los contenedores: docker rm $(docker ps -a -q)
# Borrar todas las imágenes: docker rmi $(docker images -q)
version: '2'
services:
postgresql:
build:
context: .
args:
usuario: usuario
password: password
database: mydb
ports:
- "5432:5432"
web:
environment:
PGWEB_VERSION: 0.9.6
image: s3than/pgweb
ports:
- "8080:8081"
depends_on:
- postgresql
# docker build -t postgresql .
# docker run -d -p 0.0.0.0:5432:5432 --name postgresql_inst_1 postgresql
FROM ubuntu
ARG usuario=usuario
ARG password=password
ARG database=database
RUN apt-get update
RUN apt-get install -y postgresql postgresql-contrib
# Cambiar al usuario postgres
USER postgres
# Permitir conexiones remotas
RUN echo "host all all 0.0.0.0/0 md5" >> "/etc/postgresql/$(ls /etc/postgresql)/main/pg_hba.conf"
# Escuchar cualquier conexión remota
RUN echo "listen_addresses='*'" >> "/etc/postgresql/$(ls /etc/postgresql)/main/postgresql.conf"
# Crea un usuario y una base de datos con el mismo nombre
RUN /etc/init.d/postgresql start &&\
psql --command "CREATE USER ${usuario} WITH SUPERUSER PASSWORD '${password}';" &&\
createdb -O ${usuario} ${database}
# Exponer los puertos
EXPOSE 5432
# Set the default command to run when starting the container
CMD ["bash", "-c", "/usr/lib/postgresql/$(ls /etc/postgresql)/bin/postgres -D /var/lib/postgresql/$(ls /etc/postgresql)/main -c config_file=/etc/postgresql/$(ls /etc/postgresql)/main/postgresql.conf"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment