Run Selenium in Docker Containers | Simple Solution

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this quick tutorial i'm going to show you how to dockerize selenium actually i found this solution while i was working on interview project the task was to create headless scanners that will crawl valuable data from one of freelancer website so dockerizing the scanner is really useful to handle continuous execution as well as it makes the project professional and almost production ready so let's not waste time and start by creating a new docker file it's going to be very short video hopefully because there are not too much stuff here just simple configurations next we are using python 3.7 alpine which is very lightweight image and highly recommended to keep the size as small as possible and usually it's safe in terms of compatibility and then python unbuffered is an environment variable which means that the python output is transmitted directly to the terminal without being buffered next we are going to install our dependencies by copying our requirements.txt into the docker image then we will run the pip command to start the installation next we are going to make a directory within docker image that we can use to store our application source code so basically it creates an empty folder on our docker image and then it switched to that as a default directory so any application we run using our docker container will run from this location it copies the app directory from our local machine to the docker image and that's all for the docker file yeah it's very short and simple after that create a requirements file i will add selenium and beautiful soup libraries here two legends of web scorping now create a docker compose file and the first line of docker compose configuration file is the version of docker compose that we are going to be writing our file for and then we define the services for our application below so i will define the selenium here and it pulls this standalone image port is going to be 4444. and make it always restart when the docker is up the next service is app this will our working directory we will include python files there we name the service app and then we are going to build this section of the configuration by setting the context to dot symbol which represents our current directory that running docker compose from below that we are adding volumes which allows us to get the updates in real time that we make to our project into our docker image and finally define the commands that that's used to run the application inside the docker container we will create this file we will create this file in a second and last thing is add depends on [Music] configuration great now let's create our app directory because docker docker will copy the content of this folder in here create a new file named bot.py we will take a screenshot of python.org website as a proof that it works so let's first import sleep model then we will need desired capabilities model and finally import web driver well before performing the automation our app service should wait until selenium service becomes available actually we we added depends on configuration to dock or compose file but sometimes it just fails unexpectedly that's why i will make the execution to sleep about 5 seconds next let's define our driver and here we will use webdriver.remote to connect the remote driver that we configured in compose file and the address is selenium port for 4444 slash wd hub try to visit this address in your browser and you will see the logs log stuff there and even you can manage cookies and sessions and this stuff after that we should define desired capabilities this argument because the remote driver expects this configuration once the connection established and finally go to the python.org and simply take this screenshot so that's it now let's build our project and then we will run it so it took screenshot of python.org which means it's working overall the main objective was to decorate selenium and it's really useful because by using chrome driver you can actually execute your automation in different operating systems like in mac for example but this remote driver stuff helps you to run it without any dependency errors so what about interview project you
Info
Channel: Developer Timeline
Views: 15,845
Rating: undefined out of 5
Keywords: docker selenium, selenium dockerize, docker and selenium
Id: gCWSdpLepHM
Channel Id: undefined
Length: 6min 23sec (383 seconds)
Published: Sun Jan 24 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.