Docker Community Forums

Share and learn in the Docker community.

SSH to a docker in a macvlan

docker

(Sevsev9) #1

Hello,
I ran into a problem while using container OS’s with macvlans:
I am trying to map a port to the OS (in my case the latest Ubuntu) but it wont map it afterwards.
The command i used:

docker run -it -d -p 8080:80 --name web_ubuntu --net dockernet --ip 192.168.0.152 ubuntu

Where dockernet is a macvlan:

docker network create -d macvlan --subnet=192.168.0.1/24 --gateway=192.168.0.1 -o parent=enp5s0

The container itself appears on nmap scans and I can ping it when started.
Thanks in advance.

  • CoreOS stable(1688.5.3)
  • Docker 17.12.1-ce

(David Maze) #2

If you run this command, as is, without messing with macvlan (and without specifying a --net or --ip), you’ll be able to access your container on your host’s IP address through port 8080, with no special configuration. This is kind of the normal way to use Docker; will this approach not work for you?

To answer the question in the subject line, it’s very unusual to want to “ssh to a container”: normally a container only runs a single process (in your case probably the Web server on port 80) and not a full stack of OS daemons, and maintaining the key material securely is very difficult. For debugging purposes you can ssh to the host and docker exec into the container.


(Sevsev9) #3

Thanks for the reply.
I need my container to have an individual ip address. Because i want to run more than one of the same kind at once. So the container itself is worthless to me without an IP address. Any suggestions how to do so?


(David Maze) #4

Use different ports on each instance’s -p option:

docker run -d --name web1 -p 8080:80 webserver
docker run -d --name web2 -p 8081:80 webserver
docker run -d --name web3 -p 8082:80 webserver

You’d access the three copies via the host’s IP address or DNS name on ports 8080, 8081, and 8082.


(Sevsev9) #5

I’ll try that thanks! It would’ve been easier with each container having an ip but I will try it that way thanks!