0

I have installed the ssh-server using sudo apt-get install openssh-server on my ubuntu:latest Docker container running on Mac OSX Yosemite. I got the IP address of the container using boot2docker ip. Using the Network Utility I can verify that port 22 is open on that IP. However, I cannot ssh into that container's filesystem. I did not explicity specify that port 22 should be exported when starting the container with docker start -i CONTAINER_NAME. The command ssh -v localhost succeeds on the terminal of the container but when I try to do it from my Mac's terminal, it says:

Connection closed by x.x.x.x

I am copying the contents of sshd_config here: http://collabedit.com/a76d6

ibp73
  • 650
  • 1
  • 6
  • 16
  • [docker exec](https://docs.docker.com/reference/commandline/cli/#exec) eliminates the need for running ssh inside containers. Use that instead. – Peter Lyons Mar 09 '15 at 06:01
  • @PeterLyons I want the IDEs on my Mac to be able to edit code residing in my docker container. I don't think that docker exec would let me do that smoothly? – ibp73 Mar 09 '15 at 06:28
  • Correct, but the better approach would be to use a volume for that so both your IDE on your Mac and the code in docker can directly access the files via the filesystem. – Peter Lyons Mar 09 '15 at 14:43

1 Answers1

2

With boot2docker ip you get the IP of Boot2Docker VM, not the IP of your ssh container. To connect from your Mac's terminal you should expose the port 22 of your container, and then you can connect using the Boot2Docker VM IP from your Mac session. I.E.: docker run -d -p 2222:22 CONTAINER_NAME and then connect through ssh using BOOT2DOCKER_IP and 2222 port.

Javier Cortejoso
  • 8,851
  • 3
  • 26
  • 27
  • Is there a way to expose the port on an already running container? – ibp73 Mar 09 '15 at 07:46
  • You cannot do that using Docker, but there is some workarounds you can do. Check this question to see the details http://stackoverflow.com/questions/19897743/exposing-a-port-on-a-live-docker-container – Javier Cortejoso Mar 09 '15 at 08:39