1

I know I can start sshd with CMD ["/usr/sbin/sshd","-D"] in a CentOS 7 base Docker container with docker run <debug_container_id> because I have seen it done elsewhere

  1. https://stackoverflow.com/a/25449705/1258525
  2. https://engineering.riotgames.com/news/jenkins-ephemeral-docker-tutorial
  3. https://github.com/CentOS/CentOS-Dockerfiles/blob/master/ssh/centos7/Dockerfile

I cannot get sshd to start when I run my container and I think it has something to do with my combination of a ENTRYPOINT and CMD in my Dockerfile.

Steps I take:

  1. docker run --name="<debug_container_id>" -d <debug_image>
  2. docker exec <debug_container_id> ps aux

enter image description here

You can see that my ENTRYPOINT, "dotnet TSL.Security.Service.dll" is combined with "/usr/sbin/sshd -D" in the output from docker exec <debug_container_id> ps aux

My current work around to get sshd running is:

docker exec -d <debug_container_id> bash -c "/usr/sbin/sshd -D"

With my workaround I can sssh into the container.

So you can combine ENTRYPOINT and CMD, see here though the author of the article is building a single string command to execute using ENTRYPOINT and CMD combined. I am trying to execute two command strings.

I started to realize, after rereading that article that using ENTRYPOINT and CMD together is used to build a single string command to be executed where the docker run user can override CMD arguments if desired.

Where I am trying to execute two commands on container run, so I tried changing my ENTRYPOINT to the following and removing the CMD altogether:

ENTRYPOINT ["dotnet", "TSL.Security.Service.dll", "&&", "/usr/sbin/sshd", "-D"]

This ended in the same result, sshd is not running:

enter image description here

As I investigate further, I think I am trying to launch two processes in my Docker container and that I will not be able to do this:Docker multiple entrypoints

Here is my Dockerfile for my debug_image:

FROM centos:7
MAINTAINER Brian Ogden

#Timezone
ENV TZ=America/Los_Angeles
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN yum update -y && \
         yum clean all

#############################################
# .NET Core SDK
#############################################
RUN yum install -y \
    libunwind \
    libicu

RUN curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?linkid=848821
RUN mkdir -p /opt/dotnet && tar zxf dotnet.tar.gz -C /opt/dotnet
RUN ln -s /opt/dotnet/dotnet /usr/local/bin

#speed up dotnet core builds
ENV NUGET_XMLDOC_MODE skip
ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE true
#############################################

#############################################
# Setup Container for SSH
#############################################
WORKDIR /
RUN yum install -y \
    unzip \
    openssh-server \
    curl

RUN mkdir -p /var/run/sshd
RUN echo 'root:password' | chpasswd

# SSH login fix. Otherwise user is kicked off after login
#ref https://engineering.riotgames.com/news/jenkins-ephemeral-docker-tutorial
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

# gen dummy keys, centos doesn't autogen them like ubuntu does
#ref https://engineering.riotgames.com/news/jenkins-ephemeral-docker-tutorial
RUN /usr/bin/ssh-keygen -A 

#to pass environment variables when running a Dockerized SSHD service. 
#SSHD scrubs the environment, therefore ENV variables contained in Dockerfile 
#must be pushed to /etc/profile in order for them to be available.
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
#############################################



#############################################
# .NET Sevrice setup
#############################################
#install CLRDBG, Microsoft's new cross-platform command line debugger used for debugging code running on .NET Core
RUN curl -sSL https://aka.ms/getclrdbgsh | bash /dev/stdin vs2015u2 ~/clrdbg

# Copy our code from the "/src/MyWebApi/bin/Debug/netcoreapp1.1/publish" folder to the "/app" folder in our container
WORKDIR /app
COPY ./src/TSL.Security.Service/bin/Debug/netcoreapp1.1/publish .

ARG ASPNETCORE_ENVIRONMENT
# Expose port 5000 for the Web API traffic
ENV ASPNETCORE_URLS http://+:5000
ENV ASPNETCORE_ENVIRONMENT $ASPNETCORE_ENVIRONMENT 

EXPOSE 5000 22

ENTRYPOINT ["dotnet", "TSL.Security.Service.dll"]

#############################################


#I wish this would start ssh when the container is ran but it doesn't, tried lots to get this to work
CMD ["/usr/sbin/sshd","-D"]

migrated from stackoverflow.com Aug 7 '17 at 6:56

This question came from our site for professional and enthusiast programmers.

  • Why don't you start it with service command? – Raman Sailopal Jul 12 '17 at 21:21
  • @RamanSailopal what do you mean? And did you look at how many links I provided where developers accomplished what I am trying to do? – Brian Jul 12 '17 at 21:43
  • I meant run "service sshd start" instead of sshd -D. Also, what is the error that is returned? – Raman Sailopal Jul 13 '17 at 9:51
  • @jew this is a Docker question, if you think that is not a programming question than you just work in a different type of development environment than I do, you must be more familiar with an env where software devs do not own responsibility for running their own code – Brian Jul 13 '17 at 14:06
  • @RamanSailopal yes I have tried that and that does not work, that works service be installed on the OS, calling the sshd exe file itself is more reliable again refer to.the multiple articles I included that all call /usr/sbin/sshd – Brian Jul 13 '17 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.