1

I am new to docker. I am trying to run my application using docker. However, it throws an error for me when I try to run exec -it /bin/bash command on the container error:

Error response from daemon: Container is not running

Following is my docker file (Dockerfile):
FROM openjdk:8-jdk-alpine
EXPOSE 8080
VOLUME /tmp
ADD /target/entertainment-0.0.1-SNAPSHOT.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

The steps followed:

  1. docker build -t entertainment-service .

  2. docker images, got the image id

  3. docker run command : docker run -d imageId

  4. Use postman to hit localhost:8080/entertainment - Could not get response, error connecting

  5. docker exec -it container-id /bin/bash

Error response from daemon: Container is not running

Any idea whats wrong with the Dockerfile?

1st UPDATE:

Update to the docker file

FROM java:alphine
EXPOSE 8198 - same port used in qa32 properties file
VOLUME /tmp
WORKDIR  /srv
ADD /target/entertainment-0.0.1-SNAPSHOT.jar /srv/
CMD java -jar entertainment-0.0.1-SNAPSHOT.jar

I am getting the same issue. When I try to run the jar from target using manual java command it works. Not sure what is the issue here.

2nd Update:

I am getting hibernate error while running it

Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) ~[hibernate-core-5.0.12.Final.jar!/:5.0.12.Final]
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) ~[hibernate-core-5.0.12.Final.jar!/:5.0.12.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) ~[hibernate-core-5.0.12.Final.jar!/:5.0.12.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.0.12.Final.jar!/:5.0.12.Final]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) ~[hibernate-core-5.0.12.Final.jar!/:5.0.12.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:254) ~[hibernate-core-5.0.12.Final.jar!/:5.0.12.Final]
    ... 41 common frames omitted

And up the stack I got

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_151]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_151]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_151]
  • My docker container dies in secs after starting up. Can I see the logs anywhere? – LifeStartsAtHelloWorld Mar 08 '18 at 06:18
  • Just run it without -d to see the output. – Magnus Mar 08 '18 at 06:22
  • thanks. I am getting error "Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set". Not sure why I am getting this when I run using Docker. I do have mysql connectors and dependencies mentioned in the application.properties file. I also tried running the docker pointing to the file using --env – LifeStartsAtHelloWorld Mar 08 '18 at 06:36
  • Now the issue is narrowed down to Hibernate and not docker. Check your configurations and dependencies in pom for root cause about the issue. – Ubercool Mar 08 '18 at 06:57

2 Answers2

0

Remove / after the add command, like this

ADD target/entertainment-0.0.1-SNAPSHOT.jar app.jar

Path is taken as relative to docker file so / might be causing issue. Also docker run command needs changes to map the ports between host and container.

Also make sure you have port forwarding rule created if using virtual box.

For the second issue check this question

If you trying to learn docker checkout this repo.

Ubercool
  • 1,029
  • 2
  • 14
  • 29
0

Looks like the app is unable to contact to db from docker container. If you are using external db like mysql, you need to establish link between container and external mysql.

One way to do that is to put mysql container and app container in the same network.

  1. Create a network - docker network create sample-network
  2. Create mysql container - docker create --network sample-network --name mysql-container -e MYSQL_ROOT_PASSWORD=root mysql --max-connections=300 --max-connect-errors=10000
  3. Create app container - docker create --network sample-network --name your_app_name app_image_name_here
  4. Start mysql and your app using - docker start mysql-container your_app_name
Yogesh Badke
  • 4,249
  • 2
  • 15
  • 23
  • Hi. I followed the steps. I have a question, should my app_name be mentioned in the docker file too? After following the steps, I see that the container stood up for both sql and my app. However, after few secs, my app container stopped. How can I start the container not in the background in your above step to look at the error? – LifeStartsAtHelloWorld Mar 10 '18 at 15:26
  • No, you don’t need to mention the app name in docker file. It’s just for your reference so that you know which container is running your application. To check logs, you don’t have to start container in foreground. You can do that by command ‘docker logs – Yogesh Badke Mar 11 '18 at 02:36
  • @YogeshBadke Hi, I tried your answer. My MySQL container is running. But my app is exiting automatically with exit code 1. Do you know how to resolve this? – Anne Jan 12 '22 at 07:07