标签:
浸泡了几天的官方网站,正确docker有了更好的理解。准备着手建立一个公司的开发和测试环境,包含java、python。
首先说明一下我的环境
2物理server(以后简称为主机)
主机A配置,如下面:
[root@opnvz ~]# lsb_release -a LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch Distributor ID: CentOS Description: CentOS release 6.5 (Final) Release: 6.5 Codename: Final [root@opnvz ~]# uname -a Linux opnvz 3.10.52-1.el6.elrepo.x86_64 #1 SMP Fri Aug 8 11:40:18 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux [root@opnvz ~]# docker version Client version: 1.0.0 Client API version: 1.12 Go version (client): go1.2.2 Git commit (client): 63fe64c/1.0.0 Server version: 1.0.0 Server API version: 1.12 Go version (server): go1.2.2 Git commit (server): 63fe64c/1.0.0主机B 今天还用不到,后面再介绍
这里以ubuntu14.04 为例。从openvz下载一个ubuntu14.04的模板
wget http://download.openvz.org/template/precreated/ubuntu-14.04-x86_64.tar.gz
deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
apt-get 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 在运行的时候会直接退出) [include] files = /etc/supervisor/conf.d/*.conf [program:sshd] command = /usr/sbin/sshd -D ;(加入ssh服务)<span style="font-family:Arial;"><span style="font-size: 14px; line-height: 26px;"> </span></span>
mkdir /var/run/sshd
PermitRootLogin yes
UsePAM no
root@f3c8005aa252:/etc/supervisor/conf.d# exit exit [root@opnvz start]# docker commit f3c8 ubuntu 5c21b6cf7ab3f60693f9b6746a5ec0d173fd484462b2eb0b23ecd2692b1aff6b [root@opnvz start]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu latest 5c21b6cf7ab3 6 seconds ago 512 MB<span style="font-family:Arial;"><span style="font-size: 14px; line-height: 26px;"> </span></span>
mkdir ubuntu touch ubuntu/Dockerfile vi ubuntu/Dockerfile加入例如以下内容
FROM ubuntu EXPOSE 22 CMD ["/usr/bin/supervisord"]<span style="font-family:Arial;"><span style="font-size: 14px; line-height: 26px;"> </span></span>
[root@opnvz start]# docker build -t ubuntu ubuntu/ Sending build context to Docker daemon 2.56 kB Sending build context to Docker daemon Step 0 : FROM ubuntu ---> 5c21b6cf7ab3 Step 1 : EXPOSE 22 ---> Running in 00a75d649b65 ---> 0429a60c040d Removing intermediate container 00a75d649b65 Step 2 : CMD ["/usr/bin/supervisord"] ---> Running in 49d505f56418 ---> c5d51fba9226 Removing intermediate container 49d505f56418 Successfully built c5d51fba9226<span style="font-family:Arial;"><span style="font-size: 14px; line-height: 26px;"> </span></span>
[root@opnvz start]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu latest c5d51fba9226 About a minute ago 512 MB <none> <none> 66604abb62b1 38 minutes ago 570.3 MB<span style="font-family:Arial;"><span style="font-size: 14px; line-height: 26px;"> </span></span>
docker ps -a<span style="font-family:Arial;"><span style="font-size: 14px; line-height: 26px;"> </span></span>找到刚才的容器
docker rm f3c8005aa252
docker rmi 66604abb62b1
[root@opnvz start]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu latest c5d51fba9226 About a minute ago 512 MB
标签:
原文地址:http://www.cnblogs.com/bhlsheji/p/5032260.html