skip to Main Content

I am new to docker, I have built a spring boot app that uses oracle SQL runing in a container in a port 1521:1521 When application is being run using IntelliJ all works correct but when i made this simple docker image

FROM openjdk:17-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ./target/webpage-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

build it and run it with command

docker run -p 8080:8080 webapp

I recieve error

The Network Adapter could not establish the connection

I believe its due to unability to connect with db container. How can i make it work?
Moreover this app is using enviroment variables, should they be assigned somehow to dockerfile?

2

Answers


  1. First of all i would recommend trying to figure out if you have a connection to your database from inside your docker container with using e.g.:
    docker exec -it <mycontainer> sh you can have a shell inside the container then test with telnet.
    Generally spoken this sounds more like a setup issue to me instead of a problem with the container itself.

    Login or Signup to reply.
  2. The problem is that your Docker containers are not on the same network, so they cannot connect to each other.

    There are a few ways you can put docker containers into the same network

    Use host networking. (--net=host when running your docker container)

    With this option, docker will pass through networking directly to the host, which will put all containers on the same network. This is by far the simplest option and it’s totally fine if you are testing locally but not advisable if you are running in a production environment.

    Use Docker Compose

    When you use docker compose, you can set up networks so that docker containers can see each other. This is a middle ground in terms of work and scalability and is a decent option if you are serving to a small audience or for an amateur project.

    Use a container orchestration platform like Kubernetes.

    This is most likely your best option, but also by far the most work. In this, you will deploy your containers into a cluster, with a network management system like Flannel that will facilitate network communication between pods. With this system you will be able to scale your architecture to a true production scale.

    Obviously this is just a high level introduction to your options. If you want to learn more, there’s an infinite number of options out there for learning, but this should give you an idea of what’s going on here and what you need to do in order to fix it.

    This is also the tip of the iceberg in terms of how networking works within Docker containers and I suggest you research this topic separately.

    Good luck!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search