-1

I am trying to map the port of the db-container to my containers localhost:port. Is there a way to map these ports? (I want to reach the db inside wildfly on localhost at port 12345)

currently, my db is only under oracle:1521 reachable. but I want it to be reachable under localhost:12345.

version: '3.5'
services:
  wildfly:
    image: wildfly:latest
    ports:
    - "32004:32004"
    depends_on:
    - oracle
    links:
    - oracle
  oracle:
    image: oracle-db:latest
    expose:
    - "1521"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:1521"]
      interval: 2m
      timeout: 10s
      retries: 5

Thanks

Auryn
  • 1,117
  • 1
  • 13
  • 37

1 Answers1

1

Sure, map exposed container port 1521 to host port 12345 with

ports:
    - "12345:1521"

for your oracle service like you do in the wildfly service. The pattern is HOST_PORT:EXPOSED_CONTAINER_PORT.

codinghaus
  • 2,218
  • 1
  • 14
  • 19
  • if i add the port (1234:1521) to my wildfly, i cannot reach the oracle-db under localhost. the port is not reachable from wildfly – Auryn Apr 03 '19 at 12:06
  • 1
    You don't have to add anything to wildfly. If you want to map port 1521 from your oracle service to your host port 12345 you just have to replace `expose: - "1521"` in the oracle service with `ports: - "12345:1521"`. You don't have to change anything regarding your wildfly service. – codinghaus Apr 03 '19 at 12:12
  • i probably describe my issue wrong. i want to reach the db inside of wildfly on localhost:12345. not on my host. – Auryn Apr 03 '19 at 12:14
  • 1
    Oh, I see..sorry for the misunderstanding. I have no solution for that on impulse. May I ask why you want to be able to reach it from localhost:1521 instead of oracle:1521 from within wildfly container? – codinghaus Apr 03 '19 at 12:20
  • because I don't want to change any of the application code. I only want to bring the current application into docker. – Auryn Apr 03 '19 at 12:21
  • 1
    Please have a look at https://stackoverflow.com/questions/46099874/how-can-i-forward-a-port-from-one-docker-container-to-another. It seems like it is exactly what you are trying to achieve. – codinghaus Apr 03 '19 at 12:25
  • As far as the wildfly container is concerned, `localhost` is the wildfly container. You’d connect to the database as with an `oracle` host name (the name of the service in the `docker-compose.yml`). – David Maze Apr 03 '19 at 12:46