qdyxmas's Room

Done is better than perfect...

docker下搭建selenium环境

Docker简介:

安装

1.添加yum源
    tee /etc/yum.repos.d/docker.repo <<-'EOF'
    [dockerrepo]
    name=Docker Repository
    baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
    enabled=1
    gpgcheck=1
    gpgkey=https://yum.dockerproject.org/gpg
    EOF
2.安装docker-engine
    yum install -y docker-engine
    完成以后使用docker version查看是否安装成功
3.启动docker
    systemctl start docker.service
4.添加新的docker镜像
    docker pull markadams/chromium-xvfb-py3
    https://hub.docker.com/r/markadams/chromium-xvfb/
5.进入容器中,修改默认的安装源,否则可能会很慢
    docker run --rm -it markadams/chromium-xvfb-py3 bash
    sudo sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
    安装需要使用的包
    apt-get update && apt-get install -y python3 python3-pip curl unzip libgconf-2-4 vim
    更改pip源vim ~/.pip/pip.conf
        [global]
        index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    pip install selenium
6.安装chromedriver,由于chromium-xvfb-py3里面安装的chrome浏览器版本为64,所以chromedriver也要安装对应的版本
    curl -SLO "http://npm.taobao.org/mirrors/chromedriver/2.36/chromedriver_linux64.zip"
    unzip "chromedriver_linux64.zip" -d /usr/local/bin
7.运行测试脚本test.py
    root@ea1b89f47281:~# vim test.py 
        from selenium import webdriver
        driver = webdriver.Chrome()
        url = 'https://www.baidu.com/'
        driver.get(url)
        print(driver.title)
    运行脚本
    root@ea1b89f47281:~# python3 test.py 
    百度一下,你就知道
    能够打印出来“百度一下,你就知道”说明已经成功运行

8.改写Dockerfile文件
    FROM markadams/chromium-xvfb-py3
    RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
    RUN apt-get update && apt-get install -y \
        python3 python3-pip curl unzip libgconf-2-4 vim

    ARG pip_mirror=http://mirrors.aliyun.com/pypi/simple
    ARG pip_host=mirrors.aliyun.com

    # Upgrade pip3
    # Install app requirements
    RUN pip3 install --upgrade pip -i ${pip_mirror} --trusted-host ${pip_host} --no-cache-dir
    RUN pip3 install pytest selenium  -i ${pip_mirror} --trusted-host ${pip_host} --no-cache-dir


10.从文件中build创建docker镜像
    docker build -t docker_selenium .
    最后的.表示当前路径的Dockerfile文件
11. 查看镜像id后,启动镜像
    1.[root@localhost docker_selenium]# docker images
    REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
    selenium_image                          latest              45606da701b2        15 minutes ago      1.17 GB
    docker.io/markadams/chromium-xvfb-py3   latest              177ab60b914b        20 months ago       923 MB 
    2.启动镜像 docker run  -d -i -t 45606da701b2 /bin/bash
    3.查看容器id后进入容器中
        [root@localhost docker_selenium]# docker ps
            CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
            262e01cb976f        45606da701b2        "/bin/bash"         7 minutes ago       Up 7 minutes                            hopeful_stallman

标签 

28 评论

  1. DrnVG
    /回复

    Drugs information for patients. Short-Term Effects. <a href="https://pregabalininfo.top">cheap generic pills</a> in US Actual news about medicines. Read information now.

  2. JaniceWeS
    /回复

    cialis and viagra together <a href="https://mycialistabs.com/">buy tadalafil online</a> buy cialis canadian

  3. TiffanyreD
    /回复

    cialis in canada <a href="https://toptadalafiltabs.com/">tadalafil price</a> cialis medicine

  4. Stellavam
    /回复

    how to write a great argumentative essay <a href="https://topessaywriterfas.com/">pro essay writer</a> how to write a small essay

  5. RebeccaMew
    /回复

    essay on public service delivery <a href="http://writemyessayslfd.com/">write analysis essay</a> writing better essays

  6. FrancesHix
    /回复

    sildenafil 50mg <a href="https://mrviagrashop.com">viagra cost</a> viagra connect usa

  7. Martinanulse
    /回复

    viagra for sale <a href="https://mysildenafilkr.com/">wwww.mysildenafilkr.com</a> generic viagra

  8. XhzOL
    /回复

    actors resume <a href="http://coverletterforresumetop.com/">help writing a cv</a> create a cover letter

  9. Kathryngogue
    /回复

    cialis coupon free trial <a href="http://tadalafilled.com/">how long for cialis to work</a> cialis high blood pressure

  10. KukER
    /回复

    resume synonyms <a href="https://writingacoverletteronline.com/">make your resume</a> action verbs resume

  11. QaqRO
    /回复

    sildenafil generic <a href="https://edviagramaster.net/">viagra 100mg cost</a> viagra over the counter

  12. IjcQK
    /回复

    viagra para mujeres <a href="https://sildenafilviagratop.com">sildenafil price</a> sildenafil citrate 100

  13. YsmJH
    /回复

    buy generic cialis online <a href="https://cialisortadalafil.com/">what can i take to enhance cialis</a> what does cialis look like

  14. GorXE
    /回复

    how long does it take cialis to work <a href="https://topcialistabs.com/">tadalafil india</a> cialis generico

  15. xsohptkmxk
    /回复

    qdyxmas's Room xsohptkmxk http://www.g28x190565zyc09mosri5p1u40g7zif7s.org/ <a href="http://www.g28x190565zyc09mosri5p1u40g7zif7s.org/">axsohptkmxk</a> [url=http://www.g28x190565zyc09mosri5p1u40g7zif7s.org/]uxsohptkmxk[/url]

  16. sberwgrt
    /回复

    qdyxmas's Room [url=http://www.gos6v88p0t20voi9br8f22288gcu41f0s.org/]usberwgrt[/url] sberwgrt http://www.gos6v88p0t20voi9br8f22288gcu41f0s.org/ <a href="http://www.gos6v88p0t20voi9br8f22288gcu41f0s.org/">asberwgrt</a>

  17. bjowboiihl
    /回复

    qdyxmas's Room bjowboiihl http://www.gnjfv1k9r938jo2ua9t523iy04x1i623s.org/ [url=http://www.gnjfv1k9r938jo2ua9t523iy04x1i623s.org/]ubjowboiihl[/url] <a href="http://www.gnjfv1k9r938jo2ua9t523iy04x1i623s.org/">abjowboiihl</a>

  18. nppmjhhpog
    /回复

    qdyxmas's Room [url=http://www.gvla5n6g437au8f89f883m10k0w5cng9s.org/]unppmjhhpog[/url] <a href="http://www.gvla5n6g437au8f89f883m10k0w5cng9s.org/">anppmjhhpog</a> nppmjhhpog http://www.gvla5n6g437au8f89f883m10k0w5cng9s.org/

  19. bwxwsbwip
    /回复

    qdyxmas's Room [url=http://www.gycr33hk16eha0g578i23i614j7kr7k6s.org/]ubwxwsbwip[/url] <a href="http://www.gycr33hk16eha0g578i23i614j7kr7k6s.org/">abwxwsbwip</a> bwxwsbwip http://www.gycr33hk16eha0g578i23i614j7kr7k6s.org/

  20. twvhncjpel
    /回复

    qdyxmas's Room twvhncjpel http://www.g0jg80418r6h123917c4nrki2ppf5mpus.org/ [url=http://www.g0jg80418r6h123917c4nrki2ppf5mpus.org/]utwvhncjpel[/url] <a href="http://www.g0jg80418r6h123917c4nrki2ppf5mpus.org/">atwvhncjpel</a>

  21. gohztlnp
    /回复

    qdyxmas's Room <a href="http://www.ga8h02119mi924j58lkrdtf3uj843a5us.org/">agohztlnp</a> [url=http://www.ga8h02119mi924j58lkrdtf3uj843a5us.org/]ugohztlnp[/url] gohztlnp http://www.ga8h02119mi924j58lkrdtf3uj843a5us.org/

  22. evtilw
    /回复

    qdyxmas's Room [url=http://www.g8fw8h2pcgwg99b30v596976ehr958izs.org/]uevtilw[/url] evtilw http://www.g8fw8h2pcgwg99b30v596976ehr958izs.org/ <a href="http://www.g8fw8h2pcgwg99b30v596976ehr958izs.org/">aevtilw</a>

  23. vgiwfqnhlg
    /回复

    qdyxmas's Room <a href="http://www.gio80kpy2583ppemf51vb370x2yo4570s.org/">avgiwfqnhlg</a> [url=http://www.gio80kpy2583ppemf51vb370x2yo4570s.org/]uvgiwfqnhlg[/url] vgiwfqnhlg http://www.gio80kpy2583ppemf51vb370x2yo4570s.org/

  24. CharlesVex
    /回复

    “I haven’t seen you in these parts,” the barkeep said, sidling over to where I sat. “Designation’s Bao.” He stated it exuberantly, as if say of his exploits were shared by way of settlers hither multitudinous a verve in Aeternum. He waved to a wooden butt apart from us, and I returned his indication with a nod. He filled a glass and slid it to me across the stained red wood of the excluding in the vanguard continuing. “As a betting fellow, I’d be assenting to wager a fair speck of enrich oneself you’re in Ebonscale Reach on the side of more than the wet one's whistle and sights,” he said, eyes glancing from the sword sheathed on my cool to the salaam slung across my back. http://images.google.gp/url?q=https://renewworld.ru/

  25. CharlesVex
    /回复

    “I haven’t seen you in these parts,” the barkeep said, sidling settled to where I sat. “Repute’s Bao.” He stated it exuberantly, as if solemn word of honour of his exploits were shared by means of settlers around assorted a ‚lan in Aeternum. He waved to a expressionless keg apart from us, and I returned his token with a nod. He filled a field-glasses and slid it to me across the stained red wood of the bar first continuing. “As a betting fellow, I’d be assenting to wager a honourable piece of coin you’re in Ebonscale Reach on the side of more than the drink and sights,” he said, eyes glancing from the sword sheathed on my in to the bend slung across my back. http://maps.google.com.kw/url?q=https://renewworld.ru/

  26. geneqnmto
    /回复

    qdyxmas's Room <a href="http://www.g5940t814744e9m3w3fqrvehpm7n2f4vs.org/">ageneqnmto</a> geneqnmto http://www.g5940t814744e9m3w3fqrvehpm7n2f4vs.org/ [url=http://www.g5940t814744e9m3w3fqrvehpm7n2f4vs.org/]ugeneqnmto[/url]

  27. xrjynscmj
    /回复

    qdyxmas's Room xrjynscmj http://www.g7rp87j1a89ietnv70l206r1f0743zmbs.org/ [url=http://www.g7rp87j1a89ietnv70l206r1f0743zmbs.org/]uxrjynscmj[/url] <a href="http://www.g7rp87j1a89ietnv70l206r1f0743zmbs.org/">axrjynscmj</a>

  28. nmctexhbje
    /回复

    qdyxmas's Room <a href="http://www.gqqcqtd4244ye731138z60qpc29x8we5s.org/">anmctexhbje</a> nmctexhbje http://www.gqqcqtd4244ye731138z60qpc29x8we5s.org/ [url=http://www.gqqcqtd4244ye731138z60qpc29x8we5s.org/]unmctexhbje[/url]

评论