docker composer gateway to local host

Viewed 405

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.

2 Answers

just create a shell script with all of docker-compose commands

docker-compose build
docker-compose run front apt-get install -y iproute2  
docker-compose run front ip route 
docker-compose up
Related