Docker Community Forums

Share and learn in the Docker community.

Centos6 + postgresql 9.4 service doesn't start

Hello, I try to create a docker who reproduce my production environment in Centos 6 + postgresql 9.4, this is my Dockerfile writed on the same model as found in docker documentation for ubuntu + postgresql 9.3 and modified for my environment

FROM centos:centos6

RUN yum -y update; yum clean all
RUN yum -y install epel-release; yum clean all
RUN rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-3.noarch.rpm
RUN yum -y update; yum clean all
RUN yum -y install postgresql94-server postgresql94-contrib postgresql94-devel; yum clean all

RUN service postgresql-9.4 initdb

USER postgres

RUN service postgresql-9.4 start &&
psql --command “CREATE USER docker WITH SUPERUSER PASSWORD ‘docker’;” &&
createdb -O docker dockerdb

RUN echo “host all all 0.0.0.0/0 md5” >> /var/lib/pgsql/9.4/data/pg_hba.conf
RUN echo “listen_addresses=’*’” >> /var/lib/pgsql/9.4/data/postgresql.conf

EXPOSE 5432

And this is my problem, postgresql-9.4 service doesn’t start

Step 8 : RUN service postgresql-9.4 start && psql --command “CREATE USER docker WITH SUPERUSER PASSWORD ‘docker’;” && createdb -O docker crmmbqt
—> Running in 2316099498ba
Starting postgresql-9.4 service: [FAILED]
The command ‘/bin/sh -c service postgresql-9.4 start && psql --command “CREATE USER docker WITH SUPERUSER PASSWORD ‘docker’;” && createdb -O docker crmmbqt’ returned a non-zero code: 1

I need your help, thanks by advance.

Why aren’t you just using the official postgres:9.4 image?

As a general rule, you should expect commands like service and initctl and systemctl to not work in Docker containers.

In this very specific case, if you’re on a CentOS 6 (pre-systemd) base, and service foo start just runs /etc/init.d/foo start, then your more likely problem is that you need to be root to run the init script but you’ve become a less privileged user in the line above it.

I don’t want to use the official postgres:9.4 image because my production environment run in centos6 and the official run in debian.

I have already try to run postgres by /etc/init.d/postgresql-9.4 start but same problem, and if I try to start with root privilege, service start but when I check with service postgresql-9.4 status it return the folowing message postgresql-9.4 dead but pid file exists