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 :)
Related
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!
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?
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´ve been looking in google but i cannot find any answer.
It is possible connect to a virtualbox docker container that I just start up. I have the IP of the virtual machine, but if I try to connect by SSH of course ask me for a password.
Regards.
see
https://github.com/BITPlan/docker-stackoverflowanswers/tree/master/33232371
to repeat steps.
On my Mac OS X machine
docker-machine env default
shows
export DOCKER_HOST="tcp://192.168.99.100:2376"
So i added an entry
192.168.99.100 docker
to my /etc/hosts
so that ping docker works.
As a Dockerfile i am using:
# Ubuntu image
FROM ubuntu:14.04
which I am building with
docker build -t bitplan/sshtest:0.0.1 .
and testing with
docker run -it bitplan/sshtest:0.0.1 /bin/bash
Now ssh docker will react with
The authenticity of host 'docker (192.168.99.100)' can't be established.
ECDSA key fingerprint is SHA256:osRuE6B8bCIGiL18uBBrtySH5+iGPkiHHiq5PZNfDmc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'docker,192.168.99.100' (ECDSA) to the list of known hosts.
wf#docker's password:
But here you are connecting to the docker machine not your image!
The ssh port is at port 22. You need to redirect it to another port and configure your image to support ssh to root or a valid user.
See e.g. https://docs.docker.com/examples/running_ssh_service/
Are you trying to connect to a running container or trying to connect to the virtualbox image running the docker daemon?
If the first, you cannot just SSH into a running container unless that container is running an ssh daemon. The easiest way to get a shell into a running container is with docker exec -ti <container name/id> /bin/sh. Do a docker ps to see running containers.
If the second, if your host was created with docker-machine then you can ssh into it with docker-machine ssh <machine name>. You can see all of you're running machines with docker-machine ls.
If this doesn't help can you clarify your question a little and provide details around how your creating your image and starting the container.
You can use ssh keys to access passwordless.
Here's some intro
https://wiki.archlinux.org/index.php/SSH_keys