win10家庭版安装docker&&安装centos&&安装python3.7&&运行接口测试代码

docker的安装

win10家庭版需要通过docker toolbox来安装

  • 第一步:安装docker toolbox,桌面生成三个图标:Docker Quickstart Terminal、Kitematic (Alpha)、Oracle VM VirtualBox,下方也提供了小编已下载的安装包地址
链接:https://pan.baidu.com/s/1vfhUcpNfhe7Wi1PFNfFneQ (所需安装包均在此连接上)
提取码:pusf
步骤:
1. 安装完成DockerToolbox-18.03.0-ce.exe
2. 安装完成VirtualBox
3. 再将boot2docker.iso”文件复制到“C:\Users\lenovo\.docker\machine\cache”
安装完成后打开Docker Quickstart Terminal,出现小鲸鱼即安装成功
  • 如遇到报错:Error response from daemon: client is newer than server (client API version: 1.24, server API version: 1.21)
解决方法:
1. 降低client版本即可,使用命令export DOCKER_API_VERSION=1.21
2. docker ps查看无报错即成功
  • 修改docker镜像源
1. 在Windows命令行执行docker-machine ssh [machine-name]进入VM bash
2.sudo vi /var/lib/boot2docker/profile
3. 在–label provider=virtualbox的下一行添加
--registry-mirror https://xxxxxxxx.mirror.aliyuncs.com
4. 重启docker退出

docker安装centos

1. 拉取指定版本的 CentOS 镜像,这里我们安装指定版本为例(centos7): docker pull centos:centos7
2. 运行容器,并且可以通过 exec 命令进入 CentOS 容器 docker run -itd --name centos-test centos:centos7
3. 进入容器:docker exec -it centos-test  /bin/bash
4. 退出容器:Ctrl + D
  • 再次运行容器时报错Error response from daemon: Container 1d7dd0a4a999bb6346c58b0eed286573e8139cca1d2854c543f713c2fea220c7 is not running
解决方法:
1. 运行容器docker start 1d7dd0a4a999bb6346c58b0eed286573e8139cca1d2854c543f713c2fea220c7
2. 运行镜像 docker run -itd --name centos-test centos:centos7
3. 进入容器:docker exec -it centos-test /bin/bash

centos安装python3.7

  • 安装编译相关工具
yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum install libffi-devel -y
  • 下载安装包解压
cd #回到用户目录
这个之前需要先安装 yum install wget
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
tar -xvJf  Python-3.7.0.tar.xz
  • 编译安装
mkdir /usr/local/python3 #创建编译安装目录
cd Python-3.7.0
./configure --prefix=/usr/local/python3
make && make install
  • 创建软连接
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
  • 验证是否成功
cd  /usr/local/python3/bin
python3 -V
pip3 -V

docker复制文件到宿主机

  • 查看容器id
docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
d14fabbecbbf        centos:centos7      "/bin/bash"         About an hour ago   Up About an hour                        centos-test
  • 拷贝本地文件到容器
mkdir data
docker cp D:\\pycharm\\Apitest_New.zip centos-test:\\data
拷贝容器文件到本地
docker cp aad518a6e733:/data2romedriver D:\\test
  • 进入容器执行pyhton脚本
docker exec -it centos-test /bin/bash
cd /data
unzip Apitest_New.zip
工程所在路径 /data/Apitest_New/APITEST/run.py
python3  /data/Apitest_New/APITEST/run.py  /data/Apitest_New/APITEST/project/重构APP-test.xlsm

centos中文文件乱码问题

  • 问题 ls datebase.xlsx ????APP-online.xlsm ????APP-test.xlsm ????APP-uat.xlsm
解决方法:
1.yum install vim -y
2.vim /etc/bashrc
    export LC_ALL="en_US.utf8"
    export TZ="Asia/Shanghai"
3.source /etc/bashrc
4.vim /etc/profile
	export LC_ALL="en_US.utf8"
5.source   /etc/profile
1. locale -a  (列出所有可用的公共语言环境的名称)
 2. vim /etc/sysconfig/i18n
 	LANG="zh_CN.UTF-8"
   	   LC_ALL="zh_CN.UTF-8"
  3. source    /etc/sysconfig/i18n
  4. vim /etc/locale.conf
  	LANG="zh_CN.UTF-8"
  5. source   /etc/locale.conf

centos安装谷歌浏览器

1. 拷贝谷歌浏览器到指定目录
	docker cp D:\\installpackages\\google-chrome-stable_current_x86_64.rpm centos-test:\\data
2. 进入到谷歌浏览器安装包所在路径
	rpm -ivh google-chrome-stable_current_x86_64.rpm
3. 先安装一下依赖包
	yum install redhat-lsb*
  yum -y install libXss*
  yum install libappindicator*
	yum -y install  liberation-fonts
	yum provides */libappindicator3.so.1
	yum -y install vulkan-1.1.97.0-1.el7.x86_64
4. 安装谷歌浏览器
	rpm -ivh google-chrome-stable_current_x86_64.rpm
5. 查看谷歌浏览器版本号
	google-chrome --version
  • 下载安装chromedriver(文章开头百度网盘连接里有对应的driver包)
1.下载浏览器对应driver的地址
	http://chromedriver.storage.googleapis.com/index.html?path=96.0.4664.18/
2. 将chromedriver copy到指定目录
	/usr/local/bin
  	docker cp D:\\installpackages\\chromedriver d14fabbecbbf:/usr/local/python3/bin
3. 将chromedriver配置到环境变量
	export PATH="$PATH:/usr/local/chromedriver"
  • 如果echarts报错
解决方案
1.  修改源代码进入这个py文件
	venv/lib/python3.6/site-packages/snapshot_selenium/snapshot.py
2. 按照如下修改
    def get_chrome_driver():
        options = webdriver.ChromeOptions()
        options.add_argument("headless")
        return webdriver.Chrome(options=options)
    修改为:

    def get_chrome_driver():
        options = webdriver.ChromeOptions()
        options.add_argument("headless")
        options.add_argument('--no-sandbox')
        options.add_argument('--disable-gpu')
        options.add_argument('--disable-dev-shm-usage')
        return webdriver.Chrome(options=options)