Dockerinzing Play framework
up vote
1
down vote
favorite
I am developing a web app using play fraework2.6. I am trying to have java8, postgres and nginx in my dockerfile. Here's the docker file:
FROM ubuntu:14.04
#INSTALL
RUN
echo "deb http://dl.bintray.com/sbt/debian /" | tee -a /etc/apt/sources.list.d/sbt.list
&& sudo apt-get update -y --force-yes
&& sudo apt-get install -y --force-yes sbt
RUN apt-get update && apt-get -y upgrade && apt-get -y install software-properties-common && add-apt-repository ppa:webupd8team/java -y && apt-get update
RUN (echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections) && apt-get install -y oracle-java8-installer oracle-java8-set-default
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
ENV PATH $JAVA_HOME/bin:$PATH
ENV SBT_OPTS="-Xmx2048M"
ENV SBT_OPTS="-XX:MaxPermSize=2048m"
# Add the PostgreSQL PGP key to verify their Debian packages.
# It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
# Add PostgreSQL's repository. It contains the most recent stable release
# of PostgreSQL, ``9.3``.
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
# Install ``python-software-properties``, ``software-properties-common`` and PostgreSQL 9.3
# There are some warnings (in red) that show up during the build. You can hide
# them by prefixing each apt-get statement with DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y python-software-properties postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
# Install Nginx
RUN sudo apt-get install -y nginx
# RUN echo "ndaemon off;" >> /etc/nginx/nginx.conf
# Note: The official Debian and Ubuntu images automatically ``apt-get clean``
# after each ``apt-get``
# Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed``
USER postgres
# Create a PostgreSQL role named ``docker`` with ``docker`` as the password and
# then create a database `docker` owned by the ``docker`` role.
# Note: here we use ``&&`` to run commands one after the other - the ````
# allows the RUN command to span multiple lines.
RUN /etc/init.d/postgresql start &&
psql --command "CREATE USER crm_play WITH SUPERUSER PASSWORD 'prod#123';" &&
createdb -O crm_play crm_play
# Adjust PostgreSQL configuration so that remote connections to the
# database are possible.
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
# And add ``listen_addresses`` to ``/etc/postgresql/9.3/main/postgresql.conf``
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf
# Expose the PostgreSQL port
EXPOSE 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"]
WORKDIR /java/src/project
RUN sbt update
EXPOSE 9000
ENTRYPOINT ["sbt", "run"]
COPY . /java/src/project
First of all is this the correct way to do this. Also build takes too much of time to build. I am building like this:
docker build -t image:tag .
build downloads all dependencies in sbt and other dependencies mentioned in docker file. After that I run
docker run -it -p 9000:9000 image:tag
It again starts downloading all the dependencies. What I am doing wrong here?
docker playframework-2.0
add a comment |
up vote
1
down vote
favorite
I am developing a web app using play fraework2.6. I am trying to have java8, postgres and nginx in my dockerfile. Here's the docker file:
FROM ubuntu:14.04
#INSTALL
RUN
echo "deb http://dl.bintray.com/sbt/debian /" | tee -a /etc/apt/sources.list.d/sbt.list
&& sudo apt-get update -y --force-yes
&& sudo apt-get install -y --force-yes sbt
RUN apt-get update && apt-get -y upgrade && apt-get -y install software-properties-common && add-apt-repository ppa:webupd8team/java -y && apt-get update
RUN (echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections) && apt-get install -y oracle-java8-installer oracle-java8-set-default
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
ENV PATH $JAVA_HOME/bin:$PATH
ENV SBT_OPTS="-Xmx2048M"
ENV SBT_OPTS="-XX:MaxPermSize=2048m"
# Add the PostgreSQL PGP key to verify their Debian packages.
# It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
# Add PostgreSQL's repository. It contains the most recent stable release
# of PostgreSQL, ``9.3``.
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
# Install ``python-software-properties``, ``software-properties-common`` and PostgreSQL 9.3
# There are some warnings (in red) that show up during the build. You can hide
# them by prefixing each apt-get statement with DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y python-software-properties postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
# Install Nginx
RUN sudo apt-get install -y nginx
# RUN echo "ndaemon off;" >> /etc/nginx/nginx.conf
# Note: The official Debian and Ubuntu images automatically ``apt-get clean``
# after each ``apt-get``
# Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed``
USER postgres
# Create a PostgreSQL role named ``docker`` with ``docker`` as the password and
# then create a database `docker` owned by the ``docker`` role.
# Note: here we use ``&&`` to run commands one after the other - the ````
# allows the RUN command to span multiple lines.
RUN /etc/init.d/postgresql start &&
psql --command "CREATE USER crm_play WITH SUPERUSER PASSWORD 'prod#123';" &&
createdb -O crm_play crm_play
# Adjust PostgreSQL configuration so that remote connections to the
# database are possible.
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
# And add ``listen_addresses`` to ``/etc/postgresql/9.3/main/postgresql.conf``
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf
# Expose the PostgreSQL port
EXPOSE 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"]
WORKDIR /java/src/project
RUN sbt update
EXPOSE 9000
ENTRYPOINT ["sbt", "run"]
COPY . /java/src/project
First of all is this the correct way to do this. Also build takes too much of time to build. I am building like this:
docker build -t image:tag .
build downloads all dependencies in sbt and other dependencies mentioned in docker file. After that I run
docker run -it -p 9000:9000 image:tag
It again starts downloading all the dependencies. What I am doing wrong here?
docker playframework-2.0
I don't know much about docker, but as far as I know it is generally recommended to have only one process inside a container, so you are supposed to have three containers, one for java, one for nginx, and one for postgre. You compose them with the Docker Compose. You may take ready made containers with nginx, postgre and probably with java8. (A side question, do you really need nginx? Play works better without a server in front. You generally need nginx if you serve several apps from one server).
– Ilya Posov
Nov 25 at 14:14
And about downloading dependencies, is it possible that they are downloaded in two different places? Or may be the second time that are not dependencies, but the compilation takes too long? So you can make 'sbt compile' or even 'sbt dist' in your dockerfile.
– Ilya Posov
Nov 25 at 14:15
Even more. 'sbt run' is Not for production. I propose you to call 'sbt dist' in your docker file, and then run a jar file by java, without sbt. Here is a page about going to production: playframework.com/documentation/2.6.x/Deploying, and the next topic there is about production configuration that is also may be of interest. The fact that 'sbt run' is not for production may probably be the reason, why it downloads dependencies again.
– Ilya Posov
Nov 25 at 14:23
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am developing a web app using play fraework2.6. I am trying to have java8, postgres and nginx in my dockerfile. Here's the docker file:
FROM ubuntu:14.04
#INSTALL
RUN
echo "deb http://dl.bintray.com/sbt/debian /" | tee -a /etc/apt/sources.list.d/sbt.list
&& sudo apt-get update -y --force-yes
&& sudo apt-get install -y --force-yes sbt
RUN apt-get update && apt-get -y upgrade && apt-get -y install software-properties-common && add-apt-repository ppa:webupd8team/java -y && apt-get update
RUN (echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections) && apt-get install -y oracle-java8-installer oracle-java8-set-default
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
ENV PATH $JAVA_HOME/bin:$PATH
ENV SBT_OPTS="-Xmx2048M"
ENV SBT_OPTS="-XX:MaxPermSize=2048m"
# Add the PostgreSQL PGP key to verify their Debian packages.
# It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
# Add PostgreSQL's repository. It contains the most recent stable release
# of PostgreSQL, ``9.3``.
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
# Install ``python-software-properties``, ``software-properties-common`` and PostgreSQL 9.3
# There are some warnings (in red) that show up during the build. You can hide
# them by prefixing each apt-get statement with DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y python-software-properties postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
# Install Nginx
RUN sudo apt-get install -y nginx
# RUN echo "ndaemon off;" >> /etc/nginx/nginx.conf
# Note: The official Debian and Ubuntu images automatically ``apt-get clean``
# after each ``apt-get``
# Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed``
USER postgres
# Create a PostgreSQL role named ``docker`` with ``docker`` as the password and
# then create a database `docker` owned by the ``docker`` role.
# Note: here we use ``&&`` to run commands one after the other - the ````
# allows the RUN command to span multiple lines.
RUN /etc/init.d/postgresql start &&
psql --command "CREATE USER crm_play WITH SUPERUSER PASSWORD 'prod#123';" &&
createdb -O crm_play crm_play
# Adjust PostgreSQL configuration so that remote connections to the
# database are possible.
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
# And add ``listen_addresses`` to ``/etc/postgresql/9.3/main/postgresql.conf``
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf
# Expose the PostgreSQL port
EXPOSE 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"]
WORKDIR /java/src/project
RUN sbt update
EXPOSE 9000
ENTRYPOINT ["sbt", "run"]
COPY . /java/src/project
First of all is this the correct way to do this. Also build takes too much of time to build. I am building like this:
docker build -t image:tag .
build downloads all dependencies in sbt and other dependencies mentioned in docker file. After that I run
docker run -it -p 9000:9000 image:tag
It again starts downloading all the dependencies. What I am doing wrong here?
docker playframework-2.0
I am developing a web app using play fraework2.6. I am trying to have java8, postgres and nginx in my dockerfile. Here's the docker file:
FROM ubuntu:14.04
#INSTALL
RUN
echo "deb http://dl.bintray.com/sbt/debian /" | tee -a /etc/apt/sources.list.d/sbt.list
&& sudo apt-get update -y --force-yes
&& sudo apt-get install -y --force-yes sbt
RUN apt-get update && apt-get -y upgrade && apt-get -y install software-properties-common && add-apt-repository ppa:webupd8team/java -y && apt-get update
RUN (echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections) && apt-get install -y oracle-java8-installer oracle-java8-set-default
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
ENV PATH $JAVA_HOME/bin:$PATH
ENV SBT_OPTS="-Xmx2048M"
ENV SBT_OPTS="-XX:MaxPermSize=2048m"
# Add the PostgreSQL PGP key to verify their Debian packages.
# It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
# Add PostgreSQL's repository. It contains the most recent stable release
# of PostgreSQL, ``9.3``.
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
# Install ``python-software-properties``, ``software-properties-common`` and PostgreSQL 9.3
# There are some warnings (in red) that show up during the build. You can hide
# them by prefixing each apt-get statement with DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y python-software-properties postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
# Install Nginx
RUN sudo apt-get install -y nginx
# RUN echo "ndaemon off;" >> /etc/nginx/nginx.conf
# Note: The official Debian and Ubuntu images automatically ``apt-get clean``
# after each ``apt-get``
# Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed``
USER postgres
# Create a PostgreSQL role named ``docker`` with ``docker`` as the password and
# then create a database `docker` owned by the ``docker`` role.
# Note: here we use ``&&`` to run commands one after the other - the ````
# allows the RUN command to span multiple lines.
RUN /etc/init.d/postgresql start &&
psql --command "CREATE USER crm_play WITH SUPERUSER PASSWORD 'prod#123';" &&
createdb -O crm_play crm_play
# Adjust PostgreSQL configuration so that remote connections to the
# database are possible.
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
# And add ``listen_addresses`` to ``/etc/postgresql/9.3/main/postgresql.conf``
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf
# Expose the PostgreSQL port
EXPOSE 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"]
WORKDIR /java/src/project
RUN sbt update
EXPOSE 9000
ENTRYPOINT ["sbt", "run"]
COPY . /java/src/project
First of all is this the correct way to do this. Also build takes too much of time to build. I am building like this:
docker build -t image:tag .
build downloads all dependencies in sbt and other dependencies mentioned in docker file. After that I run
docker run -it -p 9000:9000 image:tag
It again starts downloading all the dependencies. What I am doing wrong here?
docker playframework-2.0
docker playframework-2.0
asked Nov 11 at 10:22
androider
419925
419925
I don't know much about docker, but as far as I know it is generally recommended to have only one process inside a container, so you are supposed to have three containers, one for java, one for nginx, and one for postgre. You compose them with the Docker Compose. You may take ready made containers with nginx, postgre and probably with java8. (A side question, do you really need nginx? Play works better without a server in front. You generally need nginx if you serve several apps from one server).
– Ilya Posov
Nov 25 at 14:14
And about downloading dependencies, is it possible that they are downloaded in two different places? Or may be the second time that are not dependencies, but the compilation takes too long? So you can make 'sbt compile' or even 'sbt dist' in your dockerfile.
– Ilya Posov
Nov 25 at 14:15
Even more. 'sbt run' is Not for production. I propose you to call 'sbt dist' in your docker file, and then run a jar file by java, without sbt. Here is a page about going to production: playframework.com/documentation/2.6.x/Deploying, and the next topic there is about production configuration that is also may be of interest. The fact that 'sbt run' is not for production may probably be the reason, why it downloads dependencies again.
– Ilya Posov
Nov 25 at 14:23
add a comment |
I don't know much about docker, but as far as I know it is generally recommended to have only one process inside a container, so you are supposed to have three containers, one for java, one for nginx, and one for postgre. You compose them with the Docker Compose. You may take ready made containers with nginx, postgre and probably with java8. (A side question, do you really need nginx? Play works better without a server in front. You generally need nginx if you serve several apps from one server).
– Ilya Posov
Nov 25 at 14:14
And about downloading dependencies, is it possible that they are downloaded in two different places? Or may be the second time that are not dependencies, but the compilation takes too long? So you can make 'sbt compile' or even 'sbt dist' in your dockerfile.
– Ilya Posov
Nov 25 at 14:15
Even more. 'sbt run' is Not for production. I propose you to call 'sbt dist' in your docker file, and then run a jar file by java, without sbt. Here is a page about going to production: playframework.com/documentation/2.6.x/Deploying, and the next topic there is about production configuration that is also may be of interest. The fact that 'sbt run' is not for production may probably be the reason, why it downloads dependencies again.
– Ilya Posov
Nov 25 at 14:23
I don't know much about docker, but as far as I know it is generally recommended to have only one process inside a container, so you are supposed to have three containers, one for java, one for nginx, and one for postgre. You compose them with the Docker Compose. You may take ready made containers with nginx, postgre and probably with java8. (A side question, do you really need nginx? Play works better without a server in front. You generally need nginx if you serve several apps from one server).
– Ilya Posov
Nov 25 at 14:14
I don't know much about docker, but as far as I know it is generally recommended to have only one process inside a container, so you are supposed to have three containers, one for java, one for nginx, and one for postgre. You compose them with the Docker Compose. You may take ready made containers with nginx, postgre and probably with java8. (A side question, do you really need nginx? Play works better without a server in front. You generally need nginx if you serve several apps from one server).
– Ilya Posov
Nov 25 at 14:14
And about downloading dependencies, is it possible that they are downloaded in two different places? Or may be the second time that are not dependencies, but the compilation takes too long? So you can make 'sbt compile' or even 'sbt dist' in your dockerfile.
– Ilya Posov
Nov 25 at 14:15
And about downloading dependencies, is it possible that they are downloaded in two different places? Or may be the second time that are not dependencies, but the compilation takes too long? So you can make 'sbt compile' or even 'sbt dist' in your dockerfile.
– Ilya Posov
Nov 25 at 14:15
Even more. 'sbt run' is Not for production. I propose you to call 'sbt dist' in your docker file, and then run a jar file by java, without sbt. Here is a page about going to production: playframework.com/documentation/2.6.x/Deploying, and the next topic there is about production configuration that is also may be of interest. The fact that 'sbt run' is not for production may probably be the reason, why it downloads dependencies again.
– Ilya Posov
Nov 25 at 14:23
Even more. 'sbt run' is Not for production. I propose you to call 'sbt dist' in your docker file, and then run a jar file by java, without sbt. Here is a page about going to production: playframework.com/documentation/2.6.x/Deploying, and the next topic there is about production configuration that is also may be of interest. The fact that 'sbt run' is not for production may probably be the reason, why it downloads dependencies again.
– Ilya Posov
Nov 25 at 14:23
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247785%2fdockerinzing-play-framework%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I don't know much about docker, but as far as I know it is generally recommended to have only one process inside a container, so you are supposed to have three containers, one for java, one for nginx, and one for postgre. You compose them with the Docker Compose. You may take ready made containers with nginx, postgre and probably with java8. (A side question, do you really need nginx? Play works better without a server in front. You generally need nginx if you serve several apps from one server).
– Ilya Posov
Nov 25 at 14:14
And about downloading dependencies, is it possible that they are downloaded in two different places? Or may be the second time that are not dependencies, but the compilation takes too long? So you can make 'sbt compile' or even 'sbt dist' in your dockerfile.
– Ilya Posov
Nov 25 at 14:15
Even more. 'sbt run' is Not for production. I propose you to call 'sbt dist' in your docker file, and then run a jar file by java, without sbt. Here is a page about going to production: playframework.com/documentation/2.6.x/Deploying, and the next topic there is about production configuration that is also may be of interest. The fact that 'sbt run' is not for production may probably be the reason, why it downloads dependencies again.
– Ilya Posov
Nov 25 at 14:23