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

标签 

19 评论

  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/

评论