Dockerizing play framework









up vote
1
down vote

favorite












My docker compose file is:



version: '3'
services:
postgres:
container_name: crm-psql
image: postgres:9.3
restart: always
environment:
- POSTGRES_DB=crm
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root
volumes:
- ./db/postgres/data:/var/lib/postgresql/data
ports:
- 5432:5432
nginx:
container_name: crm-nginx
image: nginx:1.15
restart: always
ports:
- 80:80
- 443:443
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
web:
build: .
ports:
- 9000:9000
volumes:
- .:/src/main/java
- ~/.ivy2:/root/.ivy2
- ~/.sbt:/root/.sbt
links:
- postgres
- nginx


The docker file for build is:



FROM openjdk:8
ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk
ENV PATH $PATH:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin

ENV SBT_VERSION 1.2.1

# Install curl
RUN
apt-get update &&
apt-get -y install curl &&
apt-get -y install vim

# Install sbt
RUN
curl -L -o sbt-$SBT_VERSION.deb https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb &&
dpkg -i sbt-$SBT_VERSION.deb &&
rm sbt-$SBT_VERSION.deb &&
apt-get update &&
apt-get -y install sbt

WORKDIR /src/main/java
COPY . /src/main/java
RUN sbt update
EXPOSE 9000
ENTRYPOINT ["sbt", "run"]


Whenever I do docker-compose up, the connection doesn't gets established to postgres. The exception is




org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.




However when i exec in container crm-psql and type psql crm, it goes into postgres shell. What is the issue here










share|improve this question

























    up vote
    1
    down vote

    favorite












    My docker compose file is:



    version: '3'
    services:
    postgres:
    container_name: crm-psql
    image: postgres:9.3
    restart: always
    environment:
    - POSTGRES_DB=crm
    - POSTGRES_USER=root
    - POSTGRES_PASSWORD=root
    volumes:
    - ./db/postgres/data:/var/lib/postgresql/data
    ports:
    - 5432:5432
    nginx:
    container_name: crm-nginx
    image: nginx:1.15
    restart: always
    ports:
    - 80:80
    - 443:443
    volumes:
    - ./nginx/conf.d:/etc/nginx/conf.d
    web:
    build: .
    ports:
    - 9000:9000
    volumes:
    - .:/src/main/java
    - ~/.ivy2:/root/.ivy2
    - ~/.sbt:/root/.sbt
    links:
    - postgres
    - nginx


    The docker file for build is:



    FROM openjdk:8
    ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk
    ENV PATH $PATH:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin

    ENV SBT_VERSION 1.2.1

    # Install curl
    RUN
    apt-get update &&
    apt-get -y install curl &&
    apt-get -y install vim

    # Install sbt
    RUN
    curl -L -o sbt-$SBT_VERSION.deb https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb &&
    dpkg -i sbt-$SBT_VERSION.deb &&
    rm sbt-$SBT_VERSION.deb &&
    apt-get update &&
    apt-get -y install sbt

    WORKDIR /src/main/java
    COPY . /src/main/java
    RUN sbt update
    EXPOSE 9000
    ENTRYPOINT ["sbt", "run"]


    Whenever I do docker-compose up, the connection doesn't gets established to postgres. The exception is




    org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.




    However when i exec in container crm-psql and type psql crm, it goes into postgres shell. What is the issue here










    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      My docker compose file is:



      version: '3'
      services:
      postgres:
      container_name: crm-psql
      image: postgres:9.3
      restart: always
      environment:
      - POSTGRES_DB=crm
      - POSTGRES_USER=root
      - POSTGRES_PASSWORD=root
      volumes:
      - ./db/postgres/data:/var/lib/postgresql/data
      ports:
      - 5432:5432
      nginx:
      container_name: crm-nginx
      image: nginx:1.15
      restart: always
      ports:
      - 80:80
      - 443:443
      volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d
      web:
      build: .
      ports:
      - 9000:9000
      volumes:
      - .:/src/main/java
      - ~/.ivy2:/root/.ivy2
      - ~/.sbt:/root/.sbt
      links:
      - postgres
      - nginx


      The docker file for build is:



      FROM openjdk:8
      ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk
      ENV PATH $PATH:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin

      ENV SBT_VERSION 1.2.1

      # Install curl
      RUN
      apt-get update &&
      apt-get -y install curl &&
      apt-get -y install vim

      # Install sbt
      RUN
      curl -L -o sbt-$SBT_VERSION.deb https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb &&
      dpkg -i sbt-$SBT_VERSION.deb &&
      rm sbt-$SBT_VERSION.deb &&
      apt-get update &&
      apt-get -y install sbt

      WORKDIR /src/main/java
      COPY . /src/main/java
      RUN sbt update
      EXPOSE 9000
      ENTRYPOINT ["sbt", "run"]


      Whenever I do docker-compose up, the connection doesn't gets established to postgres. The exception is




      org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.




      However when i exec in container crm-psql and type psql crm, it goes into postgres shell. What is the issue here










      share|improve this question













      My docker compose file is:



      version: '3'
      services:
      postgres:
      container_name: crm-psql
      image: postgres:9.3
      restart: always
      environment:
      - POSTGRES_DB=crm
      - POSTGRES_USER=root
      - POSTGRES_PASSWORD=root
      volumes:
      - ./db/postgres/data:/var/lib/postgresql/data
      ports:
      - 5432:5432
      nginx:
      container_name: crm-nginx
      image: nginx:1.15
      restart: always
      ports:
      - 80:80
      - 443:443
      volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d
      web:
      build: .
      ports:
      - 9000:9000
      volumes:
      - .:/src/main/java
      - ~/.ivy2:/root/.ivy2
      - ~/.sbt:/root/.sbt
      links:
      - postgres
      - nginx


      The docker file for build is:



      FROM openjdk:8
      ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk
      ENV PATH $PATH:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin

      ENV SBT_VERSION 1.2.1

      # Install curl
      RUN
      apt-get update &&
      apt-get -y install curl &&
      apt-get -y install vim

      # Install sbt
      RUN
      curl -L -o sbt-$SBT_VERSION.deb https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb &&
      dpkg -i sbt-$SBT_VERSION.deb &&
      rm sbt-$SBT_VERSION.deb &&
      apt-get update &&
      apt-get -y install sbt

      WORKDIR /src/main/java
      COPY . /src/main/java
      RUN sbt update
      EXPOSE 9000
      ENTRYPOINT ["sbt", "run"]


      Whenever I do docker-compose up, the connection doesn't gets established to postgres. The exception is




      org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.




      However when i exec in container crm-psql and type psql crm, it goes into postgres shell. What is the issue here







      postgresql docker-compose dockerfile playframework-2.6






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 at 7:16









      androider

      428925




      428925






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          I think your problem is that you use localhost to indicate your database. You should use your link instead. From the point of view of your "sbt" container, localhost is itself and not your local machine (with the port forwarding) or your postgresql container.



          Generaly what I use is environment variables.



          links:
          - postgres
          - nginx
          environment:
          - POSTGRES_SERVICE_HOST=postgres


          After you need to specify in your SBT script how to use your POSTGRES_SERVICE_HOST variable






          share|improve this answer






















          • Made the change. Also when I do docker compose up, everything starts perfectly and then the akka server stops. Here are the logs for the same. stackoverflow.com/questions/53258307/… Can you answer this as well? Looks like the enter command is being passed to terminal through docker
            – androider
            Nov 12 at 9:23











          • Unfortunately, I have no idea of your other problem. I have never used SBT. Maybe, you can put additional information about your build.
            – Sodala
            Nov 12 at 9:58











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257416%2fdockerizing-play-framework%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          I think your problem is that you use localhost to indicate your database. You should use your link instead. From the point of view of your "sbt" container, localhost is itself and not your local machine (with the port forwarding) or your postgresql container.



          Generaly what I use is environment variables.



          links:
          - postgres
          - nginx
          environment:
          - POSTGRES_SERVICE_HOST=postgres


          After you need to specify in your SBT script how to use your POSTGRES_SERVICE_HOST variable






          share|improve this answer






















          • Made the change. Also when I do docker compose up, everything starts perfectly and then the akka server stops. Here are the logs for the same. stackoverflow.com/questions/53258307/… Can you answer this as well? Looks like the enter command is being passed to terminal through docker
            – androider
            Nov 12 at 9:23











          • Unfortunately, I have no idea of your other problem. I have never used SBT. Maybe, you can put additional information about your build.
            – Sodala
            Nov 12 at 9:58















          up vote
          1
          down vote



          accepted










          I think your problem is that you use localhost to indicate your database. You should use your link instead. From the point of view of your "sbt" container, localhost is itself and not your local machine (with the port forwarding) or your postgresql container.



          Generaly what I use is environment variables.



          links:
          - postgres
          - nginx
          environment:
          - POSTGRES_SERVICE_HOST=postgres


          After you need to specify in your SBT script how to use your POSTGRES_SERVICE_HOST variable






          share|improve this answer






















          • Made the change. Also when I do docker compose up, everything starts perfectly and then the akka server stops. Here are the logs for the same. stackoverflow.com/questions/53258307/… Can you answer this as well? Looks like the enter command is being passed to terminal through docker
            – androider
            Nov 12 at 9:23











          • Unfortunately, I have no idea of your other problem. I have never used SBT. Maybe, you can put additional information about your build.
            – Sodala
            Nov 12 at 9:58













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          I think your problem is that you use localhost to indicate your database. You should use your link instead. From the point of view of your "sbt" container, localhost is itself and not your local machine (with the port forwarding) or your postgresql container.



          Generaly what I use is environment variables.



          links:
          - postgres
          - nginx
          environment:
          - POSTGRES_SERVICE_HOST=postgres


          After you need to specify in your SBT script how to use your POSTGRES_SERVICE_HOST variable






          share|improve this answer














          I think your problem is that you use localhost to indicate your database. You should use your link instead. From the point of view of your "sbt" container, localhost is itself and not your local machine (with the port forwarding) or your postgresql container.



          Generaly what I use is environment variables.



          links:
          - postgres
          - nginx
          environment:
          - POSTGRES_SERVICE_HOST=postgres


          After you need to specify in your SBT script how to use your POSTGRES_SERVICE_HOST variable







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 at 9:09

























          answered Nov 12 at 8:54









          Sodala

          1066




          1066











          • Made the change. Also when I do docker compose up, everything starts perfectly and then the akka server stops. Here are the logs for the same. stackoverflow.com/questions/53258307/… Can you answer this as well? Looks like the enter command is being passed to terminal through docker
            – androider
            Nov 12 at 9:23











          • Unfortunately, I have no idea of your other problem. I have never used SBT. Maybe, you can put additional information about your build.
            – Sodala
            Nov 12 at 9:58

















          • Made the change. Also when I do docker compose up, everything starts perfectly and then the akka server stops. Here are the logs for the same. stackoverflow.com/questions/53258307/… Can you answer this as well? Looks like the enter command is being passed to terminal through docker
            – androider
            Nov 12 at 9:23











          • Unfortunately, I have no idea of your other problem. I have never used SBT. Maybe, you can put additional information about your build.
            – Sodala
            Nov 12 at 9:58
















          Made the change. Also when I do docker compose up, everything starts perfectly and then the akka server stops. Here are the logs for the same. stackoverflow.com/questions/53258307/… Can you answer this as well? Looks like the enter command is being passed to terminal through docker
          – androider
          Nov 12 at 9:23





          Made the change. Also when I do docker compose up, everything starts perfectly and then the akka server stops. Here are the logs for the same. stackoverflow.com/questions/53258307/… Can you answer this as well? Looks like the enter command is being passed to terminal through docker
          – androider
          Nov 12 at 9:23













          Unfortunately, I have no idea of your other problem. I have never used SBT. Maybe, you can put additional information about your build.
          – Sodala
          Nov 12 at 9:58





          Unfortunately, I have no idea of your other problem. I have never used SBT. Maybe, you can put additional information about your build.
          – Sodala
          Nov 12 at 9:58


















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257416%2fdockerizing-play-framework%23new-answer', 'question_page');

          );

          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







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          政党