2

I have a Server which has RHEL OS. I am creating a docker container inside the Server with the RHEL image as well.

My goal is to login to the docker container with a separate IP address as it was a VM.

So if the IP of the Server is 192.168.1.10 and the IP of the container inside the server is 192.168.1.15, I want to log in to both 192.168.1.10 and 192.168.1.15 as it was a separate VM. How can I achieve that?

Thanks for your help in advance.

vm345
  • 813
  • 12
  • 28
Josh
  • 31
  • 2
  • 1
    There's a lot of missing information here. First, containers generally live in a completely different address space from your host. If your host is 192.168.1.10, it is unlikely that your container is 192.168.1.15. Additionally, you haven't shown us what you've tried so far, or how you're starting the container, or how you're building the container. If you can update your question to include the relevant details we can provide you with a better answer. – larsks Dec 21 '17 at 20:56
  • Possible duplicate of [Giving a docker container a routable ip address](https://stackoverflow.com/questions/26539727/giving-a-docker-container-a-routable-ip-address) – Oliver Charlesworth Dec 21 '17 at 20:57
  • Additionally, when most people think they want to ssh into a container, the often really want something else (like, "how do I run a command in an existing container?" or something). E.g., https://stackoverflow.com/questions/30172605/how-to-get-into-a-docker-container – larsks Dec 21 '17 at 20:58
  • Sorry for the missing info. 1. Isn't it possible to have a host and container in the same subnet? 2. I have 2 NIC cards, will it be possible to use the second NIC card for IP address of the container so that both the host and container be on the same subnet. I can do docker run -it --hostname=container1 --name=container1 rhel7 /bin/bash but I want to have the static ip of the container and login into the container through ssh with that IP as it was a VM – Josh Dec 21 '17 at 21:09
  • @larsks, "when most people think they want to ssh into a container, the often really want something else" - I think, I understand why you added this comment as there is no an easy answer. The reason why the most people want SSH is that many tools and apps use SSH connection to do a job in the traditional way as they did it in VMs. They just can't easily accept the new "true religion" of the application containers. – Ruslan Jan 05 '18 at 05:03

2 Answers2

1

Short answer: you’ll need to start the container running sshd. It could be as simple as adding /usr/sbin/sshd to the run command.

Longer answer: this is not really the way docker is supposed to be used. What you probably really want is a fully functional system, with sshd started via systemd. This is a multi process fat container, and generally not considered a best practice.

easel
  • 3,982
  • 26
  • 28
0

Options are

  1. Use docker exec command
  2. Use docker attach command
  3. Start/setup sshd inside the container itself [not recommended though].

Below link details this process nicely:

https://phoenixnap.com/kb/how-to-ssh-into-docker-container

Note: This isn't my link. I found it via browsing internet.

fcdt
  • 2,371
  • 5
  • 14
  • 26
NKS
  • 21
  • 1
  • 6
  • 1
    While the link indeed does illustrates the process you should add the relevant details here to make them searchable and persistent in case the links becomes a dead link. – Markus Aug 20 '20 at 13:11