Start sshd automatically with docker container

前端 未结 7 1173
抹茶落季
抹茶落季 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 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
    

提交回复
热议问题