简体   繁体   中英

Unable to connect to remote Database using SSH tunneling from a Docker Container

My script was running completely fine in my localhost until I started running it inside a Docker Container. I do not know what went wrong. I get INFO: Connection to DB failed: due to Exception: No password or public key available! error

My db_config.py file:

with SSHTunnelForwarder(
                (<Bastian Host IP>, 22),
                ssh_username=<user>,
                ssh_pkey='oalkey.openssh',
                ssh_private_key_password=<pass>,
                remote_bind_address=(<Remote DB IP>, 1521),
                local_bind_address=('localhost', 1521)
         ) as tunnel:
            dsn_tns = 

cx_Oracle.makedsn(os.getenv("LOCAL_BIND_HOST",'localhost'),os.getenv("SSH_TUNNEL_PORT",1521),
                                        service_name=os.getenv("OCI_DSP_SERVICE","default"))
            self.db_connection = cx_Oracle.connect(os.getenv("OCI_DAS_NAME"),
                                                   os.getenv("OCI_DAS_PASS"), dsn_tns)
            logger.info('Connection to  DB successful')
        #server.stop()
    except Exception as ex:
        logger.info('Connection to DB failed! due to Exception: {}'.format(ex))

Oh, i fixed the issue. It was because the WORKDIR in my Dockerfile was pointing to the root location and I had to write the relative path in the ssh_pkey='oalkey.openssh' to ssh_pkey='app/var/www/oalkey.openssh'. Simple:-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM