Dcokerfile构建Centos-ssh镜像


创建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/init

0a075194063e723bf2bfa023a8f2d73f5199e854182cbc2a76e4a9a763093213


测试是否构建成功

[root@localhost ssh01]# docker ps -a
CONTAINER 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",



[root@localhost ssh01]# ssh -l root 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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值