0

I am attempting to ssh from a docker container into another, but the container I am trying to ssh into needs the --network host flag to be used, and therefore has no IP address.

I understand that that container is using my hosts port 22 so I changed the ssh port in the container that I am trying to ssh into to port 2200 by adding "Port 2200" to my /etc/ssh/sshd_config file

But the container still has no IP address because of the --network flag. So how do I ssh into a container that has no IP address from another container?

I am starting one container with the command

docker run --rm -it --privileged \
--network host \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /run/netns:/run/netns \
--pid="host" \
-w $CLAB_WORKDIR \
-v $CLAB_WORKDIR:$CLAB_WORKDIR \
--name sshtest \
ghcr.io/srl-labs/clab bash

The other command is just a Ubuntu container that is just started with docker run -it --name ubuntu ubuntu

1
  • 1
    Please update your question to show exactly how you are starting the two containers.
    – larsks
    Commented Mar 12 at 1:18

1 Answer 1

0

Start both containers in the same network

First, create a network with driver type, I prefer bridge:

docker network create networkie --driver bridge

You can also IP-range and subnets using --subnet and --ip-range.

Then run both containers in them:

docker start --<your flags> container-1 --network networkie`

docker start --<your flags> container-1 --network networkie`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.