Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a simple docker service accessible from external hosts

First, I inform you that i'm currently student in software development. So I beg for your tolerance regards to my question.

I'm dockerising one of my java web application. It's working fine on my Windows 10 host, connecting in localhost. But I need to make my web application accessible from other hosts, like I would do in a real life scenario.

[EDIT]: in this post docker-compose assign lan ip to service, they use some network config in docker-compose.yml. But as I said, I don't understand it enough to adapt it to my case :/

Currently, I can access my web app only from the host running the docker containers, with this url : "http://localhost:8080/public/showAtlas"

What I would like is my web app to be accessible in any browser with an url like : "http://xxx.xxx.xxx.xxx:8080/public/showAtlas" where xxx.xxx.xxx.xxx is a public IP adress that I could define in the dockerfile or docker-compose.yml

Is that possible with few config lines or is it tricky? I guess many will want to tag my question as duplicate, but I didn't find any simple answer to this simple usecase.

Could someone please help me to get this working?

I looked many online resources but the solutions are too "complex" for me to adapt it to my case.

Dockerfile of my springboot app:

FROM store/oracle/serverjre:8
VOLUME /tmp
ADD webapp/output/webapp.jar webapp.jar
ENTRYPOINT ["java", "-jar", "webapp.jar"]

Dockerfile of my database:

FROM postgres:latest
COPY db_wtc.sql /docker-entrypoint-initdb.d/init.sql

My docker-compose.yml:

version: '3.7'

services:
    db-wtc:
        build:
            context: .
            dockerfile: Dockerfile-db
        container_name: cont-db-wtc
        volumes:
            - db_data:/var/lib/postgres/data
        restart: unless-stopped
        ports:
            - 5432:5432
        expose:
            - 5432
        environment:
            POSTGRES_USER: admin_wtc
            POSTGRES_PASSWORD: 123
            POSTGRES_DB: db_wtc
        networks:
            - wtc-network

    wtc:
        depends_on:
            - db-wtc
        build:
            context: .
            dockerfile: Dockerfile
        container_name: cont-wtc
        ports:
            - 8080:8080
        expose:
            - 8080
        environment:
            SPRING_DATASOURCE_USERNAME: admin_wtc
            SPRING_DATASOURCE_PASSWORD: 123
            SPRING_DATASOURCE_URL: jdbc:postgresql://db-wtc:5432/db_wtc
        networks:
            - wtc-network

networks:
    wtc-network:

volumes:
  db_data:

No particular error. I just can't access my docker service from any external host.

Thank you guys very mush for your time!

like image 329
John Student Avatar asked Dec 04 '25 16:12

John Student


1 Answers

As I derive from the comments, this is not a docker-compose issue! The problem is that you want to access your "home" network from the public internet wich is not possible by default. You need to configure your modem to allow this.

like image 134
The Fool Avatar answered Dec 06 '25 09:12

The Fool



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!