We're learning about docker and for practice we have to SSH from the host machine into a container. I'm running Ubuntu server on VMWare Workstation. I have successfully installed SSH and the service is running. The container I've created is running on an Ubuntu image. When I try to SSH into the container by using #ssh root#ContainerIP, I get the error "Connection refused". How can I fix this?
Try the following commands.
docker ps
It will give you a list of all the working containers. Select the appropriate container in which you want to log in and pass to below command
docker exec -it container bash
It will log you in the container.
Firstly you need to install a SSH server in the images you wish to ssh-into. You can use a base image for all your container with the ssh server installed. Then you only have to run each container mapping the ssh port (default 22) to one to the host's ports (Remote Server in your image), using -p :. i.e:
docker run -p 52022:22 container1
docker run -p 53022:22 container2
Then, if ports 52022 and 53022 of hosts are accessible from outside, you can directly ssh to the containers using the IP of the host (Remote Server) specifying the port in ssh with -p . I.e.:
ssh -p 52022 myuser#RemoteServer --> SSH to container1
ssh -p 53022 myuser#RemoteServer --> SSH to container2
I think this post would help a lot: How to SSH into Docker?
Related
I am trying to create an ssh connection to a docker container I built.
I can successfully access the docker container from my remote machine using:
docker exec -it <container_name> /bin/bash
In the docker container, I modified the file /etc/ssh/sshd_config by changing:
Allowroot: yes
Setting a password in my docker container I can create a ssh connection from my remote server by using:
ssh root#localhost -p 2200
(I mapped 2200:22).
This works.
However from my local machine I am trying to connect to the docker container using:
ssh root#192.168.1.33 -p 2200 and I got permission denied.
where 192.168.1.33 is the ip adress of my remote machine where my docker container is running.
Would you have any clue?
thanks :)
ssh root#192.168.1.33 -p 2200 and I got permission denied.
where 192.168.1.33 is the ip adress of my remote machine where my docker container is running.
Would you have any clue?
thanks :)
I have a docker image, mapped the host 8888 to docker 22.
when i use another computer to ssh to host 8888, it goes into docker directly, but it's weird.
if i use 'sudo docker exec -u 0 -it xxxx /bin/bash' goes into it, when i input 'pip list', i can get the results like below
but if i ssh to docker via host 8888 port by root, it says command not found!
and if i input python from docker exec
well by ssh directly into docker, it is like this
totally different, what should i do to ssh into docker like docker exec from host, much appreciate!
I want to SSH into a directly into the bash of a docker image running on a Ubuntu VM. VM has public ip.
I want to SSH into this docker image from a remote machine. I have added the auth keys from my remote machine to my Ubuntu VM. And then started the docker image with bash on the VM with this command:
docker exec -it CONTAINER_ID bash
When I run SSH command from the remote machine as follows:
ssh -i path/to/private/key username_VM#ip_VM
I directly ssh into the Ubuntu VM but not into docker image. How to ssh directly into running docker image on the VM?
You need to expose the Docker instance's SSH port to the outside world with -p. If the host where you run this image is already using port 22 for its SSH server, you need to use a different port number.
Try e.g.
docker run -p 2222:22 yourimage
and then
ssh -i path/to/private/key -p 2222 username_VM#ip_VM
to log in to the instance over SSH.
Im running Docker Desktop for Windows (hyper V) and I need to access docker daemon from the container via tcp. It is possible to connect to it from the host like:
curl -v 127.0.0.1:2375/info but not possible to access it from a container using my host IP address. Maybe someone knows how to do that or at least how to ssh to that docker vm, for example it is possible to ssh in to it on mac by executing:
screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
I've figured how to do that using socat tool which takes docket.socket and proxy TCP calls to it.
So I've launched container with a socat which mount docker.sock since it is available inside of a VM and expose 2375 port:
docker run -p 2375:2375 -v /var/run/docker.sock:/var/run/docker.sock codenvy/socat -d -d TCP-L:2375,fork UNIX:/var/run/docker.sock
With that now, I'm able to access docker daemon API through socat container.
I am testing out running a tomcat8 on my Mac. I have the following Dockerfile:
FROM tomcat:8-jre7
MAINTAINER "Sonam Lastname <sonam#mymail.com>"
When I run the Docker container with the following command:
docker run -d -P sonam/docker-webapp
I check for the docker process by
docker ps -l
and see the port mapped at:
0.0.0.0:32769->8080/tcp
I am not able to access the tomcat page with localhost:32769 (and even tried to 8080 port).
thanks
-Sonam
Docker runs in a virtual machine when on Mac. Tomcat will listen to that network interface.
You can run docker-machine ip <name of your docker machine> and access it via that IP instead of localhost.
If on boot2docker, it is similar: boot2docker ip.