1, docker 安装
yum -y install docker-io
2, docker服务启动
service docker restart chkconfig docker on
3, docker 镜像下载
docker pull centos6
4, docker dockerfile SSH 实现
a) mkdir /data/docker/ssh -p
b) vim /data/docker/ssh/Dockerfile
FROM centos:centos6 MAINTAINER william "[email protected]" RUN yum install -y openssh-server sudo RUN sed -i ‘s/UsePAM yes/UsePAM no/g‘ /etc/ssh/sshd_config RUN useradd william RUN echo "william:william" | chpasswd RUN echo "william ALL=(ALL) ALL" >> /etc/sudoers RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key RUN mkdir /var/run/sshd EXPOSE 22 CMD ["/usr/sbin/sshd", "-D"]
5, 生成docker 镜像
docker build -t centos6-bash-ssh ssh
6, 启动docker centos6-bash-ssh 镜像
docker run -i -t centos6-bash-ssh /bin/bash
7, 验证docker centos6-bash-ssh 镜像
[[email protected] sshd]# docker attach 7977c7fee355 bash-4.1# ifconfig eth0 Link encap:Ethernet HWaddr 6E:5A:DD:C2:57:F1 inet addr:172.17.0.10 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::6c5a:ddff:fec2:57f1/64 Scope:Link UP BROADCAST RUNNING MTU:1500 Metric:1 RX packets:350 errors:0 dropped:0 overruns:0 frame:0 TX packets:206 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:39054 (38.1 KiB) TX bytes:31757 (31.0 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) bash-4.1#
[[email protected] sshd]# ssh 172.17.0.10 [email protected]‘s password: Last login: Tue Nov 11 09:43:14 2014 from 172.17.42.1 -bash-4.1#
时间: 2024-10-04 18:33:15