Ich versuche, einen Docker-Container für eine Spring Boot-Anwendung zu erstellen, die PostgreSQL als Datenbank verwendet. Mein Ziel ist es, einen Container zu erstellen, der sowohl App als auch PostgreSQL ausführt. Ich habe eine Dockerfile wie folgt:Dockerizing Spring Boot App mit Postgresql
FROM ubuntu:15.10
LABEL version="1"
ADD app.jar app.jar
RUN bash -c 'touch /app.jar'
# Install Java, Postgresql
......
USER postgres
RUN /etc/init.d/postgresql start &&\
psql --command "CREATE USER test WITH SUPERUSER PASSWORD 'test';" &&\
createdb -O test test
USER root
RUN echo "local all all trust" >> /etc/postgresql/9.4/main/pg_hba.conf
RUN echo "listen_addresses='127.0.0.1'" >> /etc/postgresql/9.4/main/postgresql.conf
RUN echo "localhost vspyfe-db" >> /etc/hosts
#Define working directory.
WORKDIR /data
# Add VOLUMEs to allow backup of config, logs and databases
VOLUME ["/tmp", "/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
# Define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
COPY ./entrypoint.sh/
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["bash", "/usr/lib/postgresql/9.4/bin/postgres", "-D", "/var/lib/postgresql/9.4/main", "-c", "config_file=/etc/postgresql/9.4/main/postgresql.conf"]
und entrypoint.sh ist:
#!/bin/sh
/etc/init.d/postgresql start
java -Djava.security.egd=file:/dev/./urandom -jar /app.jar
ich mit diesem Befehl bauen docker build --rm=true -t vspyfe/base:v1 .
und , wenn ich das Bild mit diesem Befehl docker run -i -t vspyfe/base:v1
ich Ausnahme bekam laufen, die besagt,
Caused by: org.postgresql.util.PSQLException: FATAL: role "test" does not exist
at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:471)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:112)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22)
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:32)
at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:393)
at org.postgresql.Driver.connect(Driver.java:267)
Auch wenn ich versuche Test db mit Standard-Benutzernamen und das Kennwort (postgres, postgres) zu erstellen, dann habe ich excepti on sagt, dass db nicht existiert. Ich verstehe nicht, wo ich falsch liege. In Dockerfile habe ich jeden Parameter angegeben, den ich in der Datei application.properties verwendet habe.