1. 下載ubuntu模板
這里以ubuntu14.04 為例,從openvz下載一個ubuntu14.04的模板
wget http://download.openvz.org/template/precreated/ubuntu-14.04-x86_64.tar.gz
2. 從本地鏡像import鏡像
cat ubuntu-15.10-x86_64-minimal.tar.gz |docker import - ubuntu:base
-
或者
-
使用國內(nèi)的 daocloud 的倉庫
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://cb340bea.m.daocloud.io
3. 進入虛擬機
docker run -t -i ubuntu:latest /bin/bash
3.1 更新
apt-get update
3.2 安裝supervisor服務
apt-get install supervisor cd /etc/supervisor/ cp supervisord.conf conf.d/ cd conf.d/ vi supervisord.conf
-
修改該文件如下
; supervisor config file [unix_http_server] file=/var/run/supervisor.sock ; (the path to the socket file) chmod=0700 ; sockef file mode (default 0700) [supervisord] logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP) nodaemon=true ;(修改該軟件的啟動模式為非daemon,否則docker 在執(zhí)行的時候會直接退出) [include] files = /etc/supervisor/conf.d/*.conf [program:sshd] command = /usr/sbin/sshd -D ;(添加ssh服務)
3.3 配置ssh服務
-
創(chuàng)建ssh的運行目錄
mkdir /var/run/sshd
-
更改root密碼 passwd
passwd 123456
-
允許root登陸
vi /etc/ssh/sshd_config 修改下面2個參數(shù)允許
[沒安裝ssh的話先安裝:apt-get install openssh-server]
PermitRootLogin yes UsePAM no
3.4退出docker
exit
3.5 commit最新的Ubuntu:base
docker commit f3c8 ubuntu:base
3.5 根據(jù)Dockerfile開放22端口
-
新建一個目錄
mkdir ubuntu touch ubuntu/Dockerfile vi ubuntu/Dockerfile
-
添加如下內(nèi)容
FROM ubuntu:base EXPOSE 22 CMD ["/usr/bin/supervisord"]
-
然后從這個文件創(chuàng)建image
docker build -t ubuntu:base ubuntu/
3.6 運行基礎鏡像
docker run -p 301:22 -d --name test ubuntu:base /usr/bin/supervisord
ssh 到301端口
ssh root@192.168.99.100 -p 301