3

I want to ssh into a running CentOs container running inside a CentOs image. My aim is to SSH into container and install applications into it. Please provide me appropriate steps for this.

Ran below command

 yum install openssh-server

Used below approach but did not get the result.

How to get into a docker container?

Community
  • 1
  • 1
asur
  • 1,759
  • 7
  • 38
  • 81

2 Answers2

2

You don't need to use SSH or install anything on a running container to get inside, you can use docker directly :

docker exec -it myContainer /bin/bash

Where myContainer is the name or the ID of the running container you need to connect to.

You will be then connected as root in CentOS, and you will be able to do what you need.

To leave it and go back to your host, you need to type CTRL + P - Q.

Hakro
  • 2,625
  • 1
  • 12
  • 23
  • How can I achieve installing a application like Jenkins into this container using chef-recipe? – asur Dec 13 '16 at 04:02
  • 1
    You're not on the right track mate. Containers are not meant to toy with using Chef, Puppet or Ansible. Instead, if you need to install software in a container, a much simpler proper way to go is to write a Dockerfile and build a new image. – Hakro Dec 13 '16 at 10:29
0

You can exec in the container docker exec -it myContainer /bin/bash mentioned above. But if you do not want to allow user to exec into container and then you can do this:

  1. Create a ssh key and store in file (user ssh keygen to generate key)
  2. Modify your docker image and store the key in authorized_key file in docker image. (take care of permission)
  3. Use the that key -i .ssh_key.pem to ssh in docker container.
Manoj Sahu
  • 2,774
  • 20
  • 18
  • How can I achieve installing a application like Jenkins into this container using chef-recipe? – asur Dec 13 '16 at 04:03