10

I would like to connect with SSH into my docker container. For that I created image with this Dockerfile and this command docker build -t test/toto . :

FROM ubuntu:14.04.4
MAINTAINER Darkomen <[email protected]>

# Let the conatiner know that there is no tty
ENV DEBIAN_FRONTEND noninteractive

RUN sudo apt-get -y update

RUN sudo apt-get -y install software-properties-common python-software-properties
RUN sudo add-apt-repository main
RUN sudo add-apt-repository universe
RUN sudo add-apt-repository restricted
RUN sudo add-apt-repository multiverse

RUN sudo apt-get -y update

#RUN sudo apt-get -y install linux-headers-$(uname -r) build-essential
RUN sudo apt-get -y install linux-headers-generic build-essential
RUN apt-get -y install zlib1g-dev libssl-dev libreadline-gplv2-dev
RUN apt-get -y install curl unzip
RUN apt-get -y install software-properties-common
RUN apt-get -y install gnupg2

# others tools
RUN sudo apt-get -y install nano
RUN sudo apt-get -y install vim
RUN sudo apt-get -y install aptitude
RUN sudo apt-get -y install git
RUN sudo apt-get -y install openjdk-7-jdk
RUN sudo apt-get -y install whois
RUN sudo apt-get -y install dos2unix

# SSH
RUN apt-get -y install openssh-server
RUN mkdir -p /var/run/sshd
RUN echo 'root:screencast' |chpasswd

EXPOSE 22
CMD    /usr/sbin/sshd -D

next I launched my container with this image with this command : docker run test/toto -p 42000:22

My container run perfectly and I launch this command for enter into this container : docker run -dt -p 42000:22 test/toto

Now my docker-machine and docker container (based on my dockerfile) run. I can view that because docker ps -a tell me that :

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS                   NAMES
a28ad08fd393        test/toto           "/bin/sh -c '/usr/sbi"   22 minutes ago      Up 22 minutes                 0.0.0.0:42000->22/tcp   admiring_feynman

For connecting in my container I launch this command : ssh [email protected] -p 42000

But it tell me to enter a password. I try lot of thing but nothing run. What I do forget in my process of creation and configuration docker ?

192.168.99.100 is the IP return by the docker-machine inspect command

I also tried to change root password into my container and repeat ssh command access. But nothing change. I can't connecting to container.

technical information:

  • OS : windows 7 Pro
  • Docker version : 1.12.2 build bb80604
  • Docker system : docker toolbox (based on VirtualBox)
  • VirtualBox version : 5.0.14r105127
3
  • Does docker run work? Commented Oct 30, 2016 at 15:10
  • Well, probably forgot to set up root password? Commented Oct 30, 2016 at 15:37
  • My docker run, run perfectly. I already set up root password in Dockerfile but perhaps you have more best solution... Commented Oct 30, 2016 at 15:44

2 Answers 2

14

You need to configure root login for your sshd:

Manual:

vi /etc/ssh/sshd_config

Change PermitRootLogin without-password to:

PermitRootLogin yes

Then:

service ssh restart

Now try again. If everything went fine, you need to change your docker file to make this change in the build steps.

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

2 Comments

service ssh restart generate a exit from container and stop it. I can't try this trick.
do it in your docker file then, via copy instruction, before starting ssh service.
8

Dockerfile script for create and expose a SSH connection into container :

# SSH
RUN apt-get -y install openssh-server
RUN mkdir -p /var/run/sshd

# authorize SSH connection with root account
RUN sed -i '/^#/!s/PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sudo service ssh restart

# change password root
RUN echo "root:docker"|chpasswd

1 Comment

No sudo in a Dockerfile, Dockerfile always uses sudo.

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.