Dockerfile设置sshd服务容器实例

2023-07-0910:35:09服务器及运维Comments1,008 views字数 660阅读模式

以下是用Dockerfile设置sshd服务容器,您可以使用连接并检查其他容器的卷,或者可以快速访问测试容器。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50771.html

# sshd
#
# VERSION               0.0.1

FROM     ubuntu:12.04
MAINTAINER Thatcher R. Peskens "thatcher@dotcloud.com"

# make sure the package repository is up to date
RUN apt-get update

RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:screencast' |chpasswd

EXPOSE 22
CMD    ["/usr/sbin/sshd", "-D"]

使用如下命令构建镜像:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50771.html

$ sudo docker build --rm -t eg_sshd .

然后运行它,你可以使用docker port来找出容器端口22映射到主机的端口文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50771.html

$ sudo docker run -d -P --name test_sshd eg_sshd
$ sudo docker port test_sshd 22
0.0.0.0:49154

现在你可以使用ssh登陆Docker进程的主机IP地址,端口是49154(IP地址可以使用ifconfig获取):文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50771.html

$ ssh root@192.168.1.2 -p 49154
# The password is ``screencast``.
$$

最后,清理停止的容器,并且删除容器,然后删除镜像。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50771.html

$ sudo docker stop test_sshd
$ sudo docker rm test_sshd
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/50771.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/yunwei/50771.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定