I am trying to bind port 9000 on docker container 1 (A) to port 9000 on docker container 2 (B).
I tried the --net host
option but this does not help me. I need both containers to be on the same network (172.17.0.x) and have their ports bound similar to how the -p port
flag is used to bind one container to the host. I have tried setting up listening ports on both A and B using the --expose flag
but I have been unable to bind them.
docker run -p 8080:8080\ # to bind port 8080 on A to port 8080 on the host
-it -d \
--cap-add NET_ADMIN \
--cap-add NET_RAW \
--expose 9000 \ # listening port to communicate with B
<image file>
docker run -p 8081:8081\ # to bind port 8081 on B to port 8081 on the host
-it -d \
--cap-add NET_ADMIN \
--cap-add NET_RAW \
--expose 9000 \ # listening port to communicate with B
<image file>
I would like to map A's port 9000 to B's port 9000 (or any other port) Thanks!