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

3
  • docker exec eliminates the need for running ssh inside containers. Use that instead. Commented Mar 9, 2015 at 6: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? Commented Mar 9, 2015 at 6: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. Commented Mar 9, 2015 at 14:43

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Is there a way to expose the port on an already running container?
You cannot do that using Docker, but there is some workarounds you can do. Check this question to see the details stackoverflow.com/questions/19897743/…

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.