<p>Start both containers in the same network</p>
<p>First, create a network with driver type, I prefer bridge:</p>
<pre><code>docker network create networkie --driver bridge
</code></pre>
<p>You can also IP-range and subnets using <code>--subnet</code> and <code>--ip-range</code>.</p>
<p>Then run both containers in them:</p>
<pre><code>docker start --&lt;your flags&gt; container-1 --network networkie`

docker start --&lt;your flags&gt; container-1 --network networkie`
</code></pre>

CC BY-SA 4.0
2024-03-13T10:09:18.413Z
2024-03-13T12:32:41.720Z
2024-03-13T12:32:41.720Z
Mohammed Ehab
<p>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.</p>
<p>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 &quot;Port 2200&quot; to my /etc/ssh/sshd_config file</p>
<p>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?</p>
<p>I am starting one container with the command</p>
<pre><code>docker run --rm -it --privileged \
--network host \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /run/netns:/run/netns \
--pid=&quot;host&quot; \
-w $CLAB_WORKDIR \
-v $CLAB_WORKDIR:$CLAB_WORKDIR \
--name sshtest \
ghcr.io/srl-labs/clab bash
</code></pre>
<p>The other command is just a Ubuntu container that is just started with <code>docker run -it --name ubuntu ubuntu</code></p>

CC BY-SA 4.0
2024-03-12T01:18:30.810Z
Please update your question to show exactly how you are starting the two containers.
larsks
<docker>
SSH from one docker container to another that is using --network flag?
garrett_17
# SSH from one docker container to another that is using --network flag?

(Asked by: username_0 on 2024-03-11)

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

**Tags:** docker

> **Comments:**
> **username_1**: Please update your question to show exactly how you are starting the two containers.  

---

## 1 answers

### Answer by username_2 on 2024-03-13. Score: 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 -- container-1 --network networkie`

docker start -- container-1 --network networkie`


---

