FROM docker.io/centos:7
MAINTAINER vincent huatai <vincent@huatai.me>
RUN yum clean all
RUN yum -y update
#RUN yum -y install which sudo mlocate net-tools rsyslog file ntp ntpdate \
#wget tar bzip2 screen sysstat unzip nfs-utils parted lsof man bind-utils \
#gcc gcc-c++ make telnet flex autoconf automake ncurses-devel crontabs \
#zlib-devel git openssh-clients openssh-server initscripts
RUN yum -y install which sudo openssh-clients openssh-server initscripts
# Prepare sshd host key
RUN ssh-keygen -A
# add account "admin" and give sudo privilege
RUN groupadd -g 505 admin
RUN useradd -g 505 -u 505 -d /home/admin -m admin
RUN usermod -aG wheel admin
RUN echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# Add ssh public key for login
RUN mkdir -p /home/admin/.ssh
ADD authorized_keys /home/admin/.ssh/authorized_keys
RUN chown -R admin:admin /home/admin/.ssh
RUN chmod 600 /home/admin/.ssh/authorized_keys
RUN chmod 700 /home/admin/.ssh
# run service when container started
EXPOSE 22
#CMD /usr/sbin/sshd,this is not a interactive shell
CMD ["/usr/sbin/sshd", "-D"]
sshd的参数-D是一个前台debug参数:
-D When this option is specified, sshd will not detach and does not become a daemon. This allows easy monitoring of sshd.
# HowTo use this dockerfile?
# ------ for example:
# 1. create image which name "local:centos7"
# 2. create container which name "dev7"
# --------------------------------------
# docker build -t local:centos7 .
# docker run -itd --hostname dev7 --name dev7 local:centos7
FROM docker.io/centos:7
MAINTAINER vincent huatai <vincent@huatai.me>
RUN yum clean all
RUN yum -y update
RUN yum -y install which sudo openssh-clients openssh-server initscripts
# Prepare sshd host key
RUN ssh-keygen -A
# add account "admin" and give sudo privilege
RUN groupadd -g 505 admin
RUN useradd -g 505 -u 505 -d /home/admin -m admin
RUN usermod -aG wheel admin
RUN echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# Add ssh public key for login
RUN mkdir -p /home/admin/.ssh
ADD authorized_keys /home/admin/.ssh/authorized_keys
RUN chown -R admin:admin /home/admin/.ssh
RUN chmod 600 /home/admin/.ssh/authorized_keys
RUN chmod 700 /home/admin/.ssh
# run service when container started - sshd
EXPOSE 22
#CMD ["/usr/sbin/sshd", "-D"]
# ----------
# WANT run sshd and get a bash
# ENTRYPOINT will not be override by commandline
# ----------
ENTRYPOINT /usr/sbin/sshd && /bin/bash
其他服务启动案例
以下案例同时创建了共享存储和端口映射
# creat host share storage volumedockervolumecreateshare-data# create container with port 8000 mapdockerrun-itd-p22-p8000:8000--memory=2048M--cpus="1.5"--hostnamedev7--namedev7 \-v share-data:/datalocal:centos7
或者简化一些:
docker run -itd --hostname dev7 --name dev7 -v share-data:/data local:centos7