Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker composer gateway to local host

I'm running a redis tunnel on my local machine. I want my container to connect to my local machine to then connect to the redis tunnel so that my redis credentials are kept locally.

Here is my docker-compose.yml

version: '3.8'

services:

      front:
    container_name: front_fr
    build:
      context: docker
    volumes:
      - ".:/var/www/front:rw,cached"
    environment:
      - APPLICATION_ENV=dev
    ports:
      - "443:443"
      - "6379:6379"
    extra_hosts:                                                                                                                                                                            
      - "redis.XXXX.amazonaws.com:172.23.0.1"                                                                            
      

This works fine. But I had to install iproute 2 on the container and run ip route to get the route (172.23.0.1) and add it to the extra_hosts:

   docker exec e09f640bfd0d apt-get install -y iproute2                                                                                             
   docker exec e09f640bfd0d ip route   

Is there a way to add the gateway automatically without having to manually do these steps ?

Thank you.

like image 890
Alain Zelink Avatar asked Dec 19 '25 04:12

Alain Zelink


1 Answers

If you own the docker file for this service, you can add these steps to a separate script and set it up as the ENTRYPOINT (ref. https://docs.docker.com/engine/reference/builder/#entrypoint).

If you're comfortable overriding the existing entry-point for this image, this can be done in docker-compose.yml as well (ref. https://docs.docker.com/compose/compose-file/#entrypoint)

like image 70
Ankur Avatar answered Dec 21 '25 22:12

Ankur



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!