Created
July 8, 2020 02:27
-
-
Save lambdaydoty/56a1838bce527dbd48c4bbde4be01d46 to your computer and use it in GitHub Desktop.
How to access host port from a docker container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## `How to access host port from a docker container` | |
## `Access host's ssh tunnel from docker container` | |
## `Prevent from using --net=host` | |
## ... | |
# +-------------------+ | |
# | | | |
# | | | |
# | local container | | |
# | +---+ | |
# +-------------------+ |172.10.0.1 | |
# | | |
# +-------------------+ <-+ +----------------------+ | |
# | | | | | |
# | | | | | |
# | +^-----------------+ | | |
# | local host A +-v---------------v+ remote server B | | |
# | | | | | |
# +-------------------+12345 98765+----------------------+ | |
# | |
# 1. Make sure have enabled local host A openssh server's `GatewayPorts` options | |
# (to `yes` or `clientspecified`) | |
sudo vim /etc/ssh/sshd_config | |
sudo systemctl restart ssh.service | |
# 2. Get the IP address of the `docker0` interface on your local host A | |
ip addr show docker0 # say 172.17.0.1 | |
# 3. Establish a tunnel either from local host A or from remote server B | |
ssh -N -L 172.17.0.1:12345:localhost:98765 name@remoteHostB # from local host A | |
# or | |
ssh -N -R 172.17.0.1:12345:localhost:98765 name@localHostA # from remote server B | |
# 4. Now you can access the remote server B's port 98765 | |
# from local container via 172.17.0.1:12345 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference
Powered by: http://asciiflow.com/