selenium/standalone-chrome

docker pull selenium/standalone-chrome

启动容器:

docker run -d -p 4444:4444 --shm-size=2g  -e TZ=Asia/Shanghai selenium/standalone-chrome

 

测试代码验证 可以访问容器

webdriver.Remote( command_executor="http://127.0.0.1:4444/wd/hub", desired_capabilities=DesiredCapabilities.CHROME )

 

# alpine镜像修改docker的时区

Dockerfile

FROM python:3.7.4-alpine

RUN apk add -U tzdata

RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \

  && echo 'Asia/Shanghai' >/etc/timezone

RUN pip install selenium pyyaml pytest requests pytest-repeat

CMD ["python3"]

 

 

构建新镜像:

docker build . -t selenium_python:v1

 

cat docker-compose.yml

version: "3.0"

services:

  spider:

    image: selenium_python:v1

    volumes:

      - .:/code/  

    command: ["tail","-f", "/dev/null"]

    depends_on:

      - chrome

  chrome:

    image: selenium/standalone-chrome:latest

    ports:

      - "4444:4444"

    environment:

      - TZ=Asia/Shanghai

    shm_size: 2g

  

docker-compose up -d

 

 posted on 2019-09-27 17:37  erinchen  阅读(1311)  评论(0编辑  收藏  举报