创建Dockerfile 文件
[root@localhost ~]# cd /data[root@localhost data]# mkdir ssh01
[root@localhost data]# cd ssh01/
[root@localhost ssh01]# yum install vim -y
[root@localhost ssh01]# pwd
/data/ssh01
[root@localhost ssh01]# vim Dockerfile
[root@localhost ssh01]# cat Dockerfile
# 设置基本的镜像,后续命令都以这个镜像为基础
FROM docker.io/centos:latest
# 作者信息
MAINTAINER shangwu
# RUN命令会在上面指定的镜像里执行任何命令
RUN yum install passwd openssl openssh-server -y
RUN echo '888888' | passwd --stdin root
RUN ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ''
RUN ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
RUN sed -i '/^session\s\+required\s\+pam_loginuid.so/s/^/#/' /etc/pam.d/sshd
RUN mkdir -p /root/.ssh && chown root.root /root && chmod 700 /root/.ssh
RUN yum install wget net-tools -y
RUN mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
RUN wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
RUN wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
RUN yum clean all
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8
RUN mkdir /var/run/sshd
#暴露ssh端口22
EXPOSE 22
#设定运行以daemon方式启动sshd
CMD ["/usr/sbin/sshd", "-D"]
[root@localhost ssh01]#
开始构建
[root@localhost ssh01]# docker build -t sw-centos-ssh:v1.0.1 .[root@localhost ssh01]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sw-centos-ssh v1.0.1 8abdecd1d6b5 8 seconds ago 315.2 MB
启动容器
[root@localhost ssh01]# docker run -d -p 8031:22 --name=swtest1 sw-centos-ssh:v1.0.1 /usr/sbin/init0a075194063e723bf2bfa023a8f2d73f5199e854182cbc2a76e4a9a763093213
测试是否构建成功
[root@localhost ssh01]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0a075194063e sw-centos-ssh:v1.0.1 "/usr/sbin/sshd -D" 18 seconds ago Up 15 seconds 0.0.0.0:8031->22/tcp swtest1
[root@localhost ssh01]#
[root@localhost ssh01]# docker inspect 0a075194063e | grep "IPA"
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.4",
"IPAMConfig": null,
"IPAddress": "172.17.0.4",
Centos安装httpd
安装httpd
[root@0a075194063e ~]# yum install httpd -y
修改配置
vim /etc/httpd/conf/httpd.conf
......
ServerName localhost:80
......
启动
[root@3f6a3283f006 ~]# systemctl start httpd
[root@3f6a3283f006 ~]# systemctl enable httpd
查看httpd进程
[root@0a075194063e html]# ps aux |grep httpd
root 189 0.0 0.0 12464 968 pts/0 S+ 09:54 0:00 grep --color=auto httpd
启动
[root@0a075194063e html]# httpd
[root@0a075194063e html]# ps aux |grep httpd
root 191 0.0 0.1 221936 3360 ? Ss 09:54 0:00 httpd
apache 192 0.0 0.1 221936 2940 ? S 09:54 0:00 httpd
apache 193 0.0 0.1 221936 2940 ? S 09:54 0:00 httpd
apache 194 0.0 0.1 221936 2940 ? S 09:54 0:00 httpd
apache 195 0.0 0.1 221936 2940 ? S 09:54 0:00 httpd
apache 196 0.0 0.1 221936 2940 ? S 09:54 0:00 httpd
root 198 0.0 0.0 12464 964 pts/0 S+ 09:54 0:00 grep --color=auto httpd
[root@0a075194063e html]#
停止httpd
[root@0a075194063e html]# httpd -k stop