Start sshd automatically with docker container

前端 未结 7 1174
抹茶落季
抹茶落季 2020-12-10 10:33

Given:

  • container based on ubuntu:13.10
  • installed ssh (via apt-get install ssh)

Problem: each when I start container I hav

相关标签:
7条回答
  • 2020-12-10 10:52

    Well, I used the following command to solve that

    docker run -i -t  mycentos6 /bin/bash -c '/etc/init.d/sshd start && /bin/bash'
    
    0 讨论(0)
  • 2020-12-10 10:57

    You can start ssh server when starting your container probably. Something like this:

    docker run ubuntu /usr/sbin/sshd -D
    

    Check out this official tutorial.

    0 讨论(0)
  • 2020-12-10 11:00

    This is quite an old question, but for the sake of others finding it, I think the correct way to do it would follow docker's instructions to dockerizing the ssh service.

    And in correlation to the specific question, the following lines added at the end of the dockerfile will achieve what you were looking for:

    EXPOSE 22
    CMD ["/usr/sbin/sshd", "-D"]
    

    Dockerize a SSHD service

    0 讨论(0)
  • 2020-12-10 11:01

    This is what I did:

    FROM nginx
    
    # install gosu
    # seealso:
    # https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
    # https://github.com/tianon/gosu/blob/master/INSTALL.md
    # https://github.com/tianon/gosu
    RUN set -eux; \
        apt-get update; \
        apt-get install -y gosu; \
        rm -rf /var/lib/apt/lists/*; \
    # verify that the binary works
        gosu nobody true
    
    ENV myenv='default'
    
    RUN apt-get update && apt-get install -y openssh-server
    RUN mkdir /var/run/sshd
    
    COPY entrypoint.sh /entrypoint.sh
    
    ENV AIRFLOW_HOME=/usr/local/airflow
    RUN mkdir $AIRFLOW_HOME
    RUN groupadd --gid 8080 airflow
    RUN useradd --uid 8080 --gid 8080 -ms /bin/bash -d $AIRFLOW_HOME airflow
    RUN echo 'airflow:mypass' | chpasswd
    
    
    EXPOSE 22
    CMD ["/entrypoint.sh"]
    

    Inside entrypoint.sh:

    echo "starting ssh as root"
    gosu root service ssh start &
    #gosu root /usr/sbin/sshd -D &
    
    echo "starting tail user"
    exec gosu airflow tail -f /dev/null
    
    0 讨论(0)
  • 2020-12-10 11:02

    Just try:

    ENTRYPOINT service ssh restart && bash
    

    in your dockerfile, it works fun for me!

    more details here: How to automatically start a service when running a docker container?

    0 讨论(0)
  • 2020-12-10 11:06

    You can try a more elegant way to do that with phusion/baseimage-docker

    https://github.com/phusion/baseimage-docker#readme

    0 讨论(0)
提交回复
热议问题