Dcokerfile构建Centos-ssh镜像

来源:互联网 发布:刘邦历史书籍 知乎 编辑:程序博客网 时间:2024/05/29 18:15

创建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 -yRUN echo '888888' | passwd --stdin rootRUN 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/sshdRUN mkdir -p /root/.ssh && chown root.root /root && chmod 700 /root/.sshRUN yum install wget net-tools -yRUN mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backupRUN wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repoRUN wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repoRUN yum clean allENV LANG en_US.UTF-8ENV LC_ALL en_US.UTF-8RUN mkdir /var/run/sshd#暴露ssh端口22EXPOSE  22#设定运行以daemon方式启动sshdCMD ["/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 httpdroot        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 httpdroot        191  0.0  0.1 221936  3360 ?        Ss   09:54   0:00 httpdapache      192  0.0  0.1 221936  2940 ?        S    09:54   0:00 httpdapache      193  0.0  0.1 221936  2940 ?        S    09:54   0:00 httpdapache      194  0.0  0.1 221936  2940 ?        S    09:54   0:00 httpdapache      195  0.0  0.1 221936  2940 ?        S    09:54   0:00 httpdapache      196  0.0  0.1 221936  2940 ?        S    09:54   0:00 httpdroot        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


原创粉丝点击