1.搜索镜像
jun@jun-VirtualBox:~$ sudo docker search ubuntu
jun@jun-VirtualBox:~$ sudo docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys… 13503 [OK]
dorowu/ubuntu-desktop-lxde-vnc Docker image to provide HTML5 VNC interface … 602 [OK]
websphere-liberty WebSphere Liberty multi-architecture images … 282 [OK]
rastasheep/ubuntu-sshd Dockerized SSH service, built on top of offi… 256 [OK]
consol/ubuntu-xfce-vnc Ubuntu container with "headless" VNC session… 244 [OK]
ubuntu-upstart DEPRECATED, as is Upstart (find other proces… 112 [OK]
neurodebian NeuroDebian provides neuroscience research s… 88 [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 50 [OK]
open-liberty Open Liberty multi-architecture images based… 49 [OK]
ubuntu-debootstrap DEPRECATED; use "ubuntu" instead 45 [OK]
i386/ubuntu Ubuntu is a Debian-based Linux operating sys… 28
solita/ubuntu-systemd Ubuntu + systemd 24 [OK]
1and1internet/ubuntu-16-apache-php-5.6 ubuntu-16-apache-php-5.6 14 [OK]
1and1internet/ubuntu-16-apache-php-7.0 ubuntu-16-apache-php-7.0 13 [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mariadb-10 ubuntu-16-nginx-php-phpmyadmin-mariadb-10 11 [OK]
1and1internet/ubuntu-16-nginx-php-5.6-wordpress-4 ubuntu-16-nginx-php-5.6-wordpress-4 9 [OK]
1and1internet/ubuntu-16-nginx-php-5.6 ubuntu-16-nginx-php-5.6 8 [OK]
1and1internet/ubuntu-16-apache-php-7.1 ubuntu-16-apache-php-7.1 7 [OK]
darksheer/ubuntu Base Ubuntu Image -- Updated hourly 5 [OK]
1and1internet/ubuntu-16-nginx-php-7.0 ubuntu-16-nginx-php-7.0 4 [OK]
owncloud/ubuntu ownCloud Ubuntu base image 3
1and1internet/ubuntu-16-nginx-php-7.1-wordpress-4 ubuntu-16-nginx-php-7.1-wordpress-4 3 [OK]
1and1internet/ubuntu-16-php-7.1 ubuntu-16-php-7.1 1 [OK]
smartentry/ubuntu ubuntu with smartentry 1 [OK]
1and1internet/ubuntu-16-sshd ubuntu-16-sshd 1 [OK]
jun@jun-VirtualBox:~$
2.下载镜像
jun@jun-VirtualBox:~$ sudo docker image pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
Digest: sha256:b5a61709a9a44284d88fb12e5c48db0409cfad5b69d4ff8224077c57302df9cf
Status: Image is up to date for ubuntu:latest
docker.io/library/ubuntu:latest
jun@jun-VirtualBox:~$
3.查看当前镜像
jun@jun-VirtualBox:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest d13c942271d6 9 days ago 72.8MB
hello-world latest feb5d9fea6a5 3 months ago 13.3kB
jun@jun-VirtualBox:~$
4.docker 运行,创建容器
sudo docker run -it -p 9922:22 -w /usr1 -v /home/jun/dockerfiles/file/:/usr1 ubuntu /bin/bash
-p:端口映射,「:」前为主机端口号,后面为docker里面的端口号,这里就用22连接ssh
-w:docker 挂载目录
-v:主机目录映射,「:」前为主机目录,要从根目录开始写,后面是dock里面的目录
ubuntu:镜像名称
/bin/bash:docker用bash运行
5.docker 安装ssh
5.1 安装openssh
apt-get install openssh-server
5.2 给root设置密码,设置密码如root
passwd root
5.3 修改ssh配置文件,增加 PermitRootLogin yes 注意不要拼写错误
vi /etc/ssh/sshd_config
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
5.4 重启ssh服务
root@d66a34cd1a8b:/# /etc/init.d/ssh restart
* Restarting OpenBSD Secure Shell server sshd [ OK ]
root@d66a34cd1a8b:/# exit
5.5 退出docker Ctrl+p,Ctrl+q,连续敲这两组合键一次
5.6 用ssh连接 ssh root@127.0.0.1 -p 9922,密码输入root(上面配置的密码)
5.7 设置start后自动打开ssh
image.png
编辑.bashrc文件,增加以下内容
/etc/init.d/ssh start