How to connect docker container via ssh?

I use the tutorial in this:
https://docs.docker.com/examples/running_ssh_service/
and I have finish above step, and I use the docker ps to find the port ,and assume my port is 32769 when I input this command:

ssh root@192.168.1.2 -p 32769

  • How to run Docker and node.js with remote configurations
  • How to get a docker history from an image that has not been pulled yet?
  • How to build sidekiq and rails image with docker?
  • IBM Containers: Unable to login with “cf ic login”
  • Provider docker not found - Vagrant
  • Kubernetes Workflow
  • it just show me :

    ssh root@localhost -p 32769 ssh: connect to host localhost port 32769:
    Connection refused

    this is information about command that “docker ps”:

    bash-3.2$ docker ps
    CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                    NAMES
    5e22e16a7742        liuxin/centos:ssh   "/bin/sh -c '/usr/sb   40 minutes ago      Up 40 minutes       0.0.0.0:32769->22/tcp    c_ssh_centos        
    eaa412773bb2        registry            "docker-registry"      2 hours ago         Up 2 hours          0.0.0.0:5000->5000/tcp   registry            
    

    I use the Mac OS X and have opened remote login.
    I don’t know how to make connect successed.
    Thanks

  • Docker to VM Networking
  • Error 137 on docker build command on Win7
  • Is there anyway to have a DockerBuild file use an environment variables file?
  • Docker data-only container on AWS ECS
  • Get Swarm node IP address from a container using API?
  • Dockerize ruby script that takes directories as input/output
  • One Solution collect form web for “How to connect docker container via ssh?”

    If ssh is telling you that it’s trying to connect to localhost, then that’s your problem. Docker doesn’t run natively on the Mac. Instead, it runs in a VM which has its own IP address and that’s what you need to connect to.

    Assuming you’re using docker-machine, you can do this:

    $ docker-machine ls
    NAME   ACTIVE   DRIVER         STATE     URL                          SWARM
    dev    *        vmwarefusion   Running   tcp://192.168.201.162:2376
    

    That shows that I have an active VM named “dev” as my Docker machine. Then I can run

    ssh root@$(docker-machine ip dev) -p 32769
    

    To ssh to the appropriate IP address.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.