[Docker] docker 基础学习笔记3(共6篇)

首先我们安装好了ssh server之后,
我们需要将这个容器commit,然后启动这个被commit的image。
启动方式:
docker run -d -p 2222:22 /usr/sbin/sshd -D
-d 是docker run的参数,是让docker后台运行的
-p 是进行的端口映射,把宿主linux的2222映射或者说连通到docker中操作系统的22端口,
22端口是ssh默认端口。
-D 是针对SSH的参数,此选项只是用来监视sshd的启动状态,在附加此选项时,sshd不会作为一个守 护进程启动。
 
这个时候在其他地方进行连接的时候就很简单了。
ssh root@宿主机IP地址 -p 3222
 

Ubuntu apt的用法
Kali linux 是一个编译自Debian的用于网络攻防的linux版本。
这个版本好像是linux运维的必备的版本。
 
apt-get install = yum install 也同样是有-y的。
apt-cache search XXX 的意思是搜索已经安装过的东西
运行:
apt-get install -y open-ssh
然后进行配置:
sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
sed -ri 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
sed -ri 's/#PasswordAuthentication yes/PasswordAuthentication yes/g' /etc/ssh/sshd_config

Dockerfile 重新讲解
 
dockerfile 中的命令最好大写
from :使用那个基础镜像
这个可以使用网络image,应该也是可以使用本地image的。
export : 暴露什么端口
run : 在生成image的时候运行什么操作
cmd : 在这个image运行成container的时候执行什么操作
env : ENV JAVA_HOME /data/programs/jdk
相当于linux中的 export JAVA_HOME=/data/programs/jdk
 
docker build -t kalissh:1.0 .
后边的这个点就是指的要用当前目录中的这个Dockerfile运行(D 必须大写)
现在我感觉是不是也不是必须用Dockerfile这个名字啊,已经可以指定路径
docker build -t kalissh:1.0 ./u01/docker/
docker build -t kalissh:1.0 ./u01/docker/dan-dockerfile 是不是可行?
这里是不是还要加一个 . 啊,果然要加,但是实在前边加。
 

自己制作一个dockerfile:
FROM kalilinux:1.0
 
MAINTAINER Yangjianbo/18810120658@163.com
 
RUN apt-get install -y openssh-server
RUN apt-get install -y ssh ???这个好像没有用
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
RUN sed -ri 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#PasswordAuthentication yes/PasswordAuthentication yes/g' /etc/ssh/sshd_config
RUN echo 'root:rootroot' | chpasswd
RUN /etc/init.d/ssh start ???这个是不是写成cmd更好
 
EXPORT 22
 
CMD mkdir /u01
原文地址:https://www.cnblogs.com/danjawwi/p/6133961.html