skip to Main Content

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


  1. 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
    
    Login or Signup to reply.
  2. 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)

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