Project Open Dockerfile postgres not starting - postgresql

I'm trying to use the Dockerfile provided here and on building docker build . I get the error on line 69 (RUN createuser -s projop) which reports:
Step 15/27 : RUN /usr/bin/pg_ctl -D "/var/lib/pgsql/data" start
---> Using cache
---> ce049ebe4ff5
Step 16/27 : RUN sleep 60
---> Using cache
---> bf7bac638da6
Step 17/27 : RUN createuser -s projop # database user "projop" with admin rights
---> Running in 700e6e618060
createuser: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
My inital thought was the the postgres server had not had enough time to start up from the lines before so I extended the sleep command up to 60 seconds, but I still got this same error.
I also opened a bash session with a intermediate container after the sleep with docker run -it bf7bac638da6 bash. Within this bash session I tried to manually run the createuser -s projop line which gave the same error.
However, if I reran the command /usr/bin/pg_ctl -D "/var/lib/pgsql/data" start and then createuser -s projop it would work.
This is quite od as it seems the initial start command is not taking effect. Any ideas what might be happening here?
Here's the full Dockerfile:
#
# Dockerfile for ]project-open[ V5.0 on CentOS 7
#
FROM centos:centos7
# ----------------------------------------------------------------------------------------------
# Install base packages
# ----------------------------------------------------------------------------------------------
RUN yum -y install wget net-tools setools
#RUN yum -y install cvs expat expat-devel pango graphviz-devel ImageMagick openldap-clients mlocate sharutils
# Install Perl libraries
#RUN yum -y install graphviz-perl perl perl-Archive-Tar perl-Archive-Zip perl-CGI perl-CGI-Session
#RUN yum -y install perl-CPAN perl-CPAN-Changes perl-CPAN-Meta perl-CPAN-Meta-Requirements perl-CPAN-Meta-YAML
#RUN yum -y install perl-Carp perl-Compress-Raw-Bzip2 perl-Crypt-DES perl-Crypt-OpenSSL-RSA
#RUN yum -y install perl-Crypt-OpenSSL-Random perl-Crypt-PasswdMD5 perl-Crypt-SSLeay perl-DBD-Pg
#RUN yum -y install perl-DBD-Pg-tests perl-DBI perl-Data-Dumper perl-DateTime perl-Digest-MD5
#RUN yum -y install perl-Encode perl-File-Slurp perl-GSSAPI perl-IO-Socket-IP perl-IO-Socket-SSL
#RUN yum -y install perl-JSON perl-LDAP perl-LWP-MediaTypes perl-LWP-Protocol-https perl-Net-DNS
#RUN yum -y install perl-Net-HTTP perl-Net-SSLeay perl-Params-Check perl-Params-Util perl-Params-Validate
#RUN yum -y install perl-Socket perl-TimeDate perl-WWW-Curl perl-YAML perl-core perl-devel perl-gettext
#RUN yum -y install perl-libs perl-libwww-perl rrdtool-perl perl-YAML
#RUN yum -y install libdbi-dbd-pgsql
# Install OpenOffice
#RUN yum -y install libreoffice libreoffice-headless
# ----------------------------------------------------------------------------------------------
# Download ]po[ distro files
# ----------------------------------------------------------------------------------------------
WORKDIR /usr/src/
RUN wget -q http://sourceforge.net/projects/project-open/files/project-open/Support%20Files/naviserver-4.99.8.tgz &&\
wget -q http://sourceforge.net/projects/project-open/files/project-open/Support%20Files/web_projop-aux-files.5.0.0.0.0.tgz &&\
wget -q http://sourceforge.net/projects/project-open/files/project-open/V5.0/update/project-open-Update-5.0.2.4.0.tgz
# ----------------------------------------------------------------------------------------------
# Create user projop and unpack ]po[ files an
# ----------------------------------------------------------------------------------------------
WORKDIR /usr/local
RUN tar xzf /usr/src/naviserver-4.99.8.tgz # extract the NaviServer binary 64 bit
RUN mkdir /web/ # super-directory for all Web servers /web/ by default
RUN groupadd projop # create a group called "projop"
RUN useradd -d /web/projop -g projop projop # create user "projop" with home directory /web/projop
# RUN chown -R projop:projop /web/projop # set ownership to all files
# ----------------------------------------------------------------------------------------------
# Install PostgreSQL
# ----------------------------------------------------------------------------------------------
RUN yum -y install postgresql postgresql-server postgresql-contrib
# Run the rest of the commands as user postgres
USER postgres
RUN /usr/bin/pg_ctl -D "/var/lib/pgsql/data" initdb
RUN echo "host all all 0.0.0.0/0 md5" >> /var/lib/pgsql/data/pg_hba.conf
RUN echo "listen_addresses='*'" >> /var/lib/pgsql/data/postgresql.conf
RUN /usr/bin/pg_ctl -D "/var/lib/pgsql/data" start
RUN sleep 60
RUN createuser -s projop # database user "projop" with admin rights
# ----------------------------------------------------------------------------------------------
# Setup the /web/projop folder
# ----------------------------------------------------------------------------------------------
USER projop
WORKDIR /web/projop/
RUN tar xzf /usr/src/web_projop-aux-files.5.0.0.0.0.tgz # extract auxillary files
RUN tar xzf /usr/src/project-open-Update-5.0.2.4.0.tgz # extract the ]po[ product source code - latest
RUN createdb --encoding=utf8 --owner=projop projop # new database
# RUN createlang plpgsql projop # enable PlPg/SQL, may already be installed
WORKDIR /web/projop
RUN psql -f /web/projop/pg_dump.5.0.2.4.0.sql > /web/projop/import.log 2>&1
# Expose the ]p[ and PostgreSQL port
EXPOSE 8000 5432
# Add VOLUMEs to allow backup of config, logs and databases
VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
# Set the default command to run when starting the container
CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]

Related

Enable Postgis extension Postgres in Dockerfile

How can i enable the Postgis extension in a Dockerfile? The Postgres installation is already working
this is the command in Ubuntu:
sudo -u postgres psql -c "CREATE EXTENSION postgis;"
My Dockerfile:
# Set the base image to Ubuntu
FROM ubuntu:14.04
# Update the repository sources list
RUN apt-get update -y
################## BEGIN INSTALLATION ######################
# Postgres with Postgis
# Install wget
RUN apt-get install wget -y
# Setup Postgres repository
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# Add Postgres repository
RUN sh -c "echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" >> /etc/apt/sources.list.d/postgresql.list"
# Update repository
RUN apt-get update -y
# Install Postgres with Postgis
RUN apt-get install postgresql-9.3-postgis-2.1 -y
# Change rights for start Postgresql
RUN chmod +x /etc/init.d/postgresql
# Start Postgresql
CMD service postgresql start && tail -F /var/lib/postgresql/data/serverlog
The solution for enable an extension
# Enable Postgis
RUN service postgresql start \
&& sudo -u postgres psql -c "CREATE EXTENSION postgis;"
RUN service postgresql stop
If you see other Dockerfiles using that psql -c command, like apache/marmotta Dockerfile, you will see lines like:
RUN service postgresql start \
&& psql --command "CREATE USER $DB_USER WITH PASSWORD '$DB_PASS';" \
&& psql --command "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER;"
USER root
RUN service postgresql stop
In other words, you need to make sure the postgresql service is running for those commands to succeed.

Docker Entrypoint for Postgres 9.3

This is my Dockerfile for installing Postgres.
# Set the base image to Ubuntu
FROM ubuntu:14.04
# Update the repository sources list
RUN apt-get update -y
################## BEGIN INSTALLATION ######################
# Install wget
RUN apt-get install wget -y
# Setup Postgres repository
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc
| sudo apt-key add -
# Add Postgres repository
RUN sh -c "echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" >> /etc/apt/sources.list.d/postgresql.list"
# Update repository
RUN apt-get update -y
# Install Postgres with Postgis
RUN apt-get install postgresql-9.3-postgis-2.1 -y
How can i add an Entrypoint for Postgres so that Postgres is automatically started in a Docker-container
My solution to start Postgres automatic:
RUN chmod +x /etc/init.d/postgresql
CMD service postgresql start && tail -F /var/lib/postgresql/data/serverlog
You can take ideas from the official docker-library/postgres Dockerfile:
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 5432
CMD ["postgres"]
They use a docker-entrypoint.sh script which will, at the end, launch postgres
exec gosu postgres "$#"

How to install webacula 7 on centos 7

this is a tutorial to install webacula 7 (after bacula 7 with mysql)
this is the tutorial for centos+bcula that i used (without webmin section)
http://www.backupcentral.com/phpBB2/two-way-mirrors-of-external-mailing-lists-3/bacula-25/howto-install-bacula-7-on-centos-7-fresh-install-126395/
Then to install webacula:
yum install httpd php php-mysql php-gd
wget http://downloads.sourceforge.net/project/webacula/webacula/7.0.0/webacula-7.0.0.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fwebacula%2F%3Fsource%3Dtyp_redirect&ts=1429012567&use_mirror=garr
(download webacula 7.0.0)
yum install httpd php php-mysql
tar -xzvf /root/webacula-7.0.0.tar.gz\?r\=http...
mv webacula-7.0.0 /var/www/
mv /var/www/webacula-7.0.0/ /var/www/webacula
chown -R root.root .
chown apache.apache cache
groupadd bacula
usermod -aG bacula apache
chgrp bacula /usr/sbin/bconsole
/etc/bacula/bconsole.conf
chgrp bacula /etc/bacula/bconsole.conf
cd ../application
nano config.ini
update:
bacula.bconsole = "/usr/sbin/bconsole"
bacula.bconsolecmd = "-n -c /etc/bacula/bconsole.conf"
nano /etc/sudoers
comment:
# Defaults requiretty
nano /etc/bacula/bconsole.conf
update:
Password = "YOUR PASS"
nano /etc/selinux/config
update:
SELINUX=disabled
nano /etc/sudoers.d/apache
add:
apache ALL=NOPASSWD: /usr/sbin/bconsole
reboot (because the selinux)
check with this command:
su -l apache -s /bin/sh -c "/usr/bin/sudo /usr/sbin/bconsole -n -c /etc/bacula/bconsole.conf"
normal respons :
Connecting to Director localhost:9101
1000 OK: 1 bacula-dir Version: 7.0.5 (28 July 2014)
Enter a period to cancel a command.
*quit
cd /var/www/webacula/install/apache/
cp webacula.conf /etc/httpd/conf.d/webacula.conf
nano /etc/httpd/conf.d/webacula.conf
update:
Alias /webacula /usr/share/webacula/html
<Directory /usr/share/webacula/html>
...
Deny from all
to:
Alias /webacula /var/www/webacula/html
<Directory /var/www/webacula/html>
...
Allow from all
nano /var/www/webacula/application/config.ini
update your db pass
nano /etc/bacula/bacula-dir.conf
update :
catalog = all, !skipped, !saved
cd /var/www/webacula/install
./password-to-hash.php your bacula webming pass
take ther respons and put in:
nano db.conf
update:
db_pwd="your root mysql pass"
....
webacula_root_pwd="your res from ./password-to-hash.php"
cd MySql/
./10_make_tables.sh
./20_acl_make_tables.sh
systemctl restart httpd
add Zend to webacula:
cd /var/www/webacula/library
wget https://packages.zendframework.com/releases/ZendFramework-1.12.3/ZendFramework-1.12.3-minimal.tar.gz (download only ver 1.12.3!!!!!!)
tar -xzf ZendFramework-1.12.3-minimal.tar.gz
mkdir Zend
cp -Rf ZendFramework-1.12.3-minimal/library/Zend/* Zend/.
go to website :)
now we finished but for me the root password did not work, so to fix this i did:
mysql -uroot -p
use bacula;
update webacula_users set email='your email here';
go to website and reset password

How to start railo service in background on the Docker

My name Trang,
I have created Docker image on https://registry.hub.docker.com/u/trangunghoa/railo-mysql/
It is run ok.
Now I created Dockerfile but I can't start automatic Railo service. Please help me.
I have start by some commands at shell script:
exec /opt/railo/railo_ctl start
exec /opt/railo/railo_ctl start -D FOREGROUND
service railo_ctl restart
exec service railo_ctl restart
No command it work.
I looked inside your Dockerfile and identified the problem.
You can only use one CMD inside a Dockerfile. (if you use multiple CMD the old one will override) More info : https://docs.docker.com/reference/builder/#cmd
You need to know that Docker isn't made for running multiple process without a little bit of help. I suggest using supervisord : https://docs.docker.com/articles/using_supervisord/
You can't use RUN service inside a Dockerfile, the reason is simple the command service will be executed and start a daemon, then notify the execution was successful. The temporary container will be killed (and the daemon too) and after that the change will be committed.
What your Dockerfile should look like :
FROM ubuntu:trusty
MAINTAINER Trang Lee <trangunghoa#gmail.com>, Seta International Vietnam(info#setacinq.vn)
#Install base packages
RUN apt-get -y update
RUN apt-get install -y openjdk-7-jre-headless
RUN apt-get install -y tomcat7 tomcat7-admin apache2 libapache2-mod-jk
RUN apt-get purge -y openjdk-6-jre-headless icedtea-6-jre-cacao openjdk-6-jre-lib icedtea-6-jre-jamvm
RUN apt-get install -y supervisor
# config to enable .htaccess
ADD apache_default /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
# start service
ADD start-apache2.sh /start-apache2.sh
ADD railo.sh /railo.sh
ADD run.sh /run.sh
RUN chmod +x /*.sh
#RUN sudo service apache2 start
# install railo
RUN apt-get install -y wget
RUN wget http://www.getrailo.org/railo/remote/download42/4.2.1.000/tomcat/linux/railo-4.2.1.000-pl2-linux-x64-installer.run
RUN chmod -R 744 railo-4.2.1.000-pl2-linux-x64-installer.run
RUN ./railo-4.2.1.000-pl2-linux-x64-installer.run --mode unattended --railopass “123456”
# remove railo setup
#RUN rm -rf railo-4.2.1.000-pl2-linux-x64-installer.run
#RUN sudo service railo_ctl start
RUN mkdir -p /etc/service/railo
ADD start-railo.sh /etc/service/railo/run
RUN chmod 755 /etc/service/railo/run
# EXPOSE <port>
EXPOSE 80 8888
#CMD ["/railo.sh"]
#CMD ["/start-apache2.sh"]
# Supervisord configuration
RUN mkdir /var/log/supervisor
ADD ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord"]
With your supervisord.conf file looking something like that :
[supervisord]
nodaemon=true
[program:apache2]
command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"
[program:railo]
command=/bin/bash -c "exec /opt/railo/railo_ctl start -D FOREGROUND"

Docker doesn't start MONGODB, and IPAddress doesn't appear, when started with other services

I have already asked this question on serverfault.com. I am asking it here too as I see different set of questions in these 2 sites (it appears like they have different databases).
I have been trying to build an OS image from Fedora unsuccessfully to start the following:
Systemd
SSHD
RabbitMQ
MongoDB
I can get the first 3 (Systemd, SSHD and RabbitMQ-Server) to work. I can also get MongoDB to work within the container. However, I cannot get MongoDB to work along with other 3 services.
In addition, IP address doesn't show up when I try to "dockerize" MongoDB.
Am I missing something in the Dockerfile?
Here is my dockerfile:
FROM fedora:20
MAINTAINER “Ashfaque” <ashfaque#email.com>
ENV container docker
RUN yum -y update; yum clean all
RUN yum -y install systemd; yum clean all; \
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
# Dockerizing SSH - is working
RUN yum -y install openssh-server
RUN yum -y install openssh-clients
RUN mkdir /var/run/sshd
RUN systemctl enable sshd.service
RUN echo 'root:mypassword' |chpasswd
EXPOSE 22
# Dockerizing RabbitMQ - is working
RUN yum -y install rabbitmq-server
EXPOSE 5672 15672
RUN systemctl enable rabbitmq-server
# Dockerizing MongoDB - is NOT WORKING
RUN yum -y install mongodb-server
RUN yum -y install boost
RUN yum -y install scons
# Create the MongoDB data directory
RUN mkdir -p /data/db /var/log/mongodb /var/run/mongodb
RUN sed -i 's/dbpath =\/var\/lib\/mongodb/dbpath =\/data\/db/' /etc/mongodb.conf
# Expose port 27017 from the container to the host
EXPOSE 27017
# Set usr/bin/mongod as the dockerized entry-point application
ENTRYPOINT ["/usr/bin/mongod"]
#CMD ["--port", "27017", "--dbpath", "/data/db", "--smallfiles", "--fork", "--syslog"]
#RUN /usr/bin/mongod --smallfiles --port 27017 --dbpath /data/db --fork --syslog
VOLUME ["/sys/fs/cgroup", "/data/db", "/var/log/mongodb", "/usr/bin"]
CMD ["/usr/sbin/init"]
Docker Commands used to build are:
(1) docker build -t rabbitmq_mongo_heisenbug .
(2) docker run --privileged -d -e 'container=docker' -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 29022:22 -p 29672:15672 -p 29017:27017 rabbitmq_mongo_heisenbug
or.. (3) docker run --privileged -ti -e 'container=docker' -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 29022:22 -p 29672:15672 -p 29017:27017 rabbitmq_mongo_heisenbug
You are using both ENTRYPOINT and CMD in your Dockerfile. This means, that docker will run /usr/bin/mongod with default parameter /usr/sbin/init. I'm pretty sure this is not what you want.
Docker will run as long as the command you specified is running. I'm not sure about /usr/bin/mongod, but if it runs in daemon mode (that is, spawn a process and return), then the container will stop running right away. The spawned processes will be terminated. The same is true for /usr/sbin/init or for any other command you specify. You can write a small shell script, which spawns the processes and runs one in the foreground, or you can use runit, or some similar tool.
Also, you probably don't need to run sshd in your container. See here why.