2017-08-08更新: carina容器已下线.
一、基础配置
远程连接容器
source ./ub/docker.env
下载第三方ubuntu镜像
wget http://download.openvz.org/template/precreated/ubuntu-14.04-x86_64.tar.gz
上传镜像并挂载
cat ubuntu-14.04-x86_64.tar.gz |./docker import - ubuntu:base
安装镜像至容器,不能使用22,2376,7946,8300,8400,8600端口
./docker run --name ubuntu -p 80:80 -p 220:22 -p 666:666 -p 8787:8787 -p 3306:3306 -p 21:21 -p 443:443 -t -i ubuntu:base /bin/bash
更新
apt-get update
安装MySQL
apt-get install mysql-server mysql-client
设置mysql的配置文件
vi /etc/mysql/my.cnf
找到 bind-address =127.0.0.1 将其注释掉;//作用是使得不再只允许本地访问;
重启mysql:
/etc/init.d/mysql restart;
安装apache2
apt-get install apache2
安装php5
apt-get install php5 libapache2-mod-php5 apt-get install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
不可跳过,否则apache2出错
mkdir /run/lock
重启apache2
/etc/init.d/apache2 restart
配置ssh登录
service ssh start
重新连接
./docker exec -it wordpress su
设置密码
./docker exec -it wordpress passwd
删掉容器
./docker rm 容器名字
二、快速配置
#上传镜像并启用,设置root密码,改成你的名称
1 | source ./web5/docker.env ; cat ubuntu-14.04-x86_64.tar.gz |docker import - ubuntu:base |
#启动ssh服务,配置安装环境等
1 | service ssh start ; mkdir /run/lock |
#配置代码等
1 | service postfix start |
三、建立cron计划任务
- #修复connect refuse问题dpkg-divert --local --rename --add /sbin/initctl ln -s /bin/true /sbin/initctl
#编辑cron表
crontab -e
- 选择编辑器,推荐vi和vim
按键盘上的字母 i 进行编辑
在最底部正确添加语法,格式*/1 * * * * curl " http://localhost/cron/qsigntask.php?sys=1&key=305694 " */1 * * * * curl " http://localhost/cron/qzonetask.php?sys=1&key=305694 " */1 * * * * curl " http://localhost/cron/zantask.php?sys=1&key=305694 " */1 * * * * curl " http://localhost/cron/qsigntask.php?sys=1&key=305694 " */1 * * * * curl " http://localhost/cron/wsigntask.php?sys=1&key=305694 " */1 * * * * curl " http://localhost/cron/wztask.php?sys=1&key=305694 " */1 * * * * curl " http://localhost/cron/newsid.php?&key=305694 "
编辑好后,按一下ESC,然后键入:wq保存
启动cron
service cron start
如果提示
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service cron restart
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the stop(8) and then start(8) utilities,
e.g. stop cron ; start cron. The restart(8) utility is also available.
则应该这样启动:
cron start/running
或者,自定义pid:
cron start/running, process 6328
若提示找不到pid什么的:
rm -rf /var/run/crond.pid
若还不行,试试重装cron:
apt-get install --reinstall cron
使用以下的其中一条命令可停止cron:
cron stop/waiting service cron stop
四、启用https
开启SSL模块
a2enmod ssl
编辑配置文件
vi /etc/apache2/sites-enabled/000-default.conf
添加以下内容(示例)
ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLEngine on SSLCertificateFile /etc/ssl/iikira/2_kk.iikira.com.crt SSLCertificateKeyFile /etc/ssl/iikira/kk.iikira.com_key SSLCertificateChainFile /etc/ssl/iikira/1_root_bundle.crt
重启服务
service apache2 restart
五、生成全部端口
注意,无法使用22,2376,7946,8300,8400,8600端口,有需要的请替换别的,如-p 220:22 译为 远程访问[server_ip]:220 将被宿主机重定向到内部容器的22端口 从而实现ssh登录。
1 | javascript:var a={},i,d="";for(i=1;i<10086;i++){a[i]="-p "+i+":"+i+" ";d+=a[i]};document.write("docker run --name ubuntu "+d+"-t -i ubuntu:base /bin/bash"); |