2019年1月

之前一直听到的声音是,openvz6的机器不能安装docker,
但是只有openvz才会有大内存多处理器的便宜机器
现在,好消息来了,只要你的机器内核不是特别老,且主机商愿意在母鸡上加一个小小的参数,你就可以运行docker了


首先,你需要登陆主机,查看系统内核版本

uname -r

一般会出现类似 2.6.32-042stab134.8的版本,如果042stab后面的数字(xxx.x)大于等于105.4的话,恭喜你,你的vps可以安装docker

你可以选择centos7系统,也可以选择ubuntu 16.04(低于这个版本,因为没有systemctl,会更麻烦),为了避免主机商拒绝你,我建议你安装centos7,因为openvz官方文档是这样写的
注意先备份数据,有时候服务商可能需要删除你的机器,并重装
紧接着,你需要给服务商发一个工单,比如这样写

Hello, admin:
I would like to install docker on my openvz server, the
openvz official document said that it can be done simply by setup two
flags on the openvz host https://wiki.openvz.org/Docker_inside_CT
Could you please consider assist me ? you can feel free to format or
reinstall my machine

我来解释下官方文档操作的含义

#Container creation and tuning 容器创建和调整的过程:
#Create CentOS 7 container with enough disk space: 创建一个有充足磁盘空间的CentOS 7 容器
vzctl create $veid --ostemplate centos-7-x86_64 --diskspace 20G
#Turn on bridge feature to allow docker creating bridged network: 开启桥接功能使得docker可以创建桥接网络
vzctl set $veid --features bridge:on --save
#Setup Container veth-based network: 设置容器的基于veth的网络接口
vzctl set $veid --netif_add eth0 --save
#Allow all iptables modules to be used in containers:#允许容器使用完整的iptables模块
vzctl set $veid --netfilter full --save
#Enable tun device access for container: 允许容器使用tun设备
vzctl set $veid --devnodes net/tun:rw --save
#Configure custom cgroups in systemd: 在systemd设置自定义的cgroups
#systemd reads /proc/cgroups and mounts all cgroups enabled there, though it doesn't know there's a restriction that only freezer,devices and cpuacct,cpu,cpuset can be mounted in container, but not freezer, cpu etc. separately 
#systemd 读取/proc/cgroups 并挂载所有开启的cgroups,但是他不知道只有freezer,devices和 cpuacct,cpu,cpuset可以被挂载,但是单独的freezer, cpu等等不能被挂载
vzctl mount $veid
echo "JoinControllers=cpu,cpuacct,cpuset freezer,devices" >> /vz/root/$veid/etc/systemd/system.conf
#Start the container: 开启容器
vzctl start $veid

如果服务商操作完毕了,接下来你需要登陆服务器
假设你的服务器安装的是CentOS 7

如果你安装了默认的docker,必须删除干净,运行如下命令

yum remove docker docker-common

紧接着,安装docker1.10,注意只有1.10和更老的版本可以使用

vi /etc/yum.repos.d/docker.repo

按下i键,进入插入模式
粘贴如下内容

[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

按一下ESC,按一下:,输入wq,按下回车,就退出来了
然后安装docker1.10

yum install docker-engine-1.10.3

你可以会发现如下错误


You will get the following error after install:
FATA[0000] Your Linux kernel version 2.6.32-042stab125.5 is unstable running Docker. Please 
upgrade your kernel to 3.10+.

别着急,还差最后一步,执行下面命令

echo "JoinControllers=cpu,cpuacct,cpuset freezer,devices" >> /etc/systemd/system.conf
mkdir -p /etc/docker/ && echo '{"storage-driver": "vfs"}' > /etc/docker/daemon.json

然后尝试再次启动

sudo systemctl start docker
docker run hello-world

如果成功,你会看到如下消息

    
Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

问题来了,哪个主机商会配合你?
我亲测可以的 n3server
推荐机型
3GB OpenVZ

3GB RAM
3GB SWAP
4 x CPU Core
120GB HDD Space
5TB Bandwidth
1Gbps
1 x IPv4
OpenVZ/SolusVM
$9/qtr or $25/yr
注册
购买
请用我的推广链接注册来支持我
还有一个2核的,不推荐
1.5GB OpenVZ

1.5GB RAM
1.5GB SWAP
2 x CPU Core
60GB HDD Space
3TB Bandwidth
1Gbps
1 x IPv4
OpenVZ/SolusVM
$6/qtr or $15/yr
注册
购买
请用我的推广链接注册来支持我

参考文献:
Getting PlexGuide/Docker to work on OpenVZ
How To Install specific Docker version on Linux Machine.
Docker_inside_CT

truffle migrate命令执行时出现如下错误
Attempting to run transaction which calls a contract function, but recipient address is not a contract address
原因:build里面有旧的编译状态,而你的ganache已经重置了
解决方法:重置编译状态,执行 truffle migrate --reset

truffle compile常见问题
SyntaxError: Source file requires different compiler version (current compiler is 0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.24;
^----------------------^
solc编译器版本和合约要求的无法兼容,truffle目前很难换编译器,这种问题只能升级,降级truffle版本,比如上面这条错误,就需要把truffle从5.0降级到4.1.15
命令如下

npm uninstall -g truffle
npm i -g [email protected]