Build a docker of google chrome and runs python scripts inside

Dear All,

I am trying to use “docker” instead of “virtual machine” for running simple application - “chrome browser”.

Simply, I have python file consists of about 30 lines, it works fine now without docker (in the virtual machine). Actually I want to make it works inside a docker instead of virtual machine. I have already learned how to setup a docker image and run some scripts inside, but seems something I could not know to make my python file works.

So I would really appreciate it if you could help me out at resolving the issue I am currently facing. The issues is as follows.

First, I run the docker image pulled from hub.docker,

sudo docker run -p 4444:4444 selenium/standalone-chrome

Second, I run following python file “run.py” from the host machine, sudo python run.py

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

driver = webdriver.Remote(“http://127.0.0.1:4444/wd/hub”, DesiredCapabilities.CHROME)
driver.get(‘https://www.google.com’);
driver.save_screenshot(‘shd1’)
driver.quit()

I would like to launch the “run.py” in the container instead for run it from the host machine. That is, I would run both chrome driver and python code in the same container.
I would appreciate it if anyone could help out.

Thanks so much
Aljby