1、下载centos7镜像: ...

2、启动镜像并防止退出:

docker run -it centos:7 top

3、进入镜像: docker exec -it xxxxId bash

执行:
	mkdir /software
	rm -rf /etc/yum.repos.d/*.repo

4、复制文件进入容器

docker cp ./CentOS-Base.repo containerIdxxxxx:/etc/yum.repos.d (注意repo镜像文件要可用,自己网上找找)
docker cp ./epel.repo containerIdxxxxx:/etc/yum.repos.d (注意repo镜像文件要可用,自己网上找找)
docker cp ./start.sh containerIdxxxxx:/software
docker cp ./client.ovpn containerIdxxxxx:/software/client.ovpn  (client.ovpn根据服务器配置生成,自行从服务器导出或手动编写配置)
start.sh文件内容:
#!/bin/sh
mkdir /dev/net
mknod /dev/net/tun c 10 200
chmod 600 /dev/net/tun
echo -e "${1}\n${2}">/software/user
echo "user/pass docker run -e 'APP_OPTS=userxx passxxx'"
openvpn --config /software/client.ovpn --auth-user-pass /software/user

5、进入镜像安装openvpn: docker exec -it xxxxId bash

执行:
	
	yum install -y openvpn

如果yum 包pki错误,可以安装
	cd /etc/pki/rpm-gpg
	wget https://archive.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7

6、提交镜像:

docker commit -a="作者xxx" -m="描述xxx" containerIdxxxxx openvpn-client:V2.4

7、重新打包镜像,设置启动脚本和环境变量: dockerfile如下:

FROM openvpn-client:V2.4
ENV APP_OPTS=""
ENTRYPOINT [ "sh", "-c", "/software/start.sh $APP_OPTS"]

8、运行镜像:

docker run -e "APP_OPTS=moyz2 QQ20xxQQs" -it --privileged openvpn-client:V2.4