WebDriverException: Message: invalid argument: can't kill an exited process in a Docker container returns odd errors - selenium

I'm running a small Python script that scrapes some data from a public website.
When I run the Dockerfile instructions line by line in an interactive terminal using the selenium:latest image the script runs fine.
docker run -it -v /Users/me/Desktop/code/scraper/:/scraper selenium/standalone-firefox bash
As soon as I run it using my Dockerfile and docker-compose file I get this error:
app_1 | selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
I am using the MOZ_HEADLESS=1 env var. It's being passed properly.
I have tried running the script as someone other than root but then I get log errors.
Dockerfile
FROM selenium/standalone-firefox:latest
# https://github.com/SeleniumHQ/docker-selenium/issues/725
USER root
RUN apt-get update -y
RUN apt-get install -y firefox python-pip
WORKDIR /scraper
COPY . /scraper
RUN pip install -r /scraper/requirements.txt
ENV MOZ_HEADLESS=1
CMD ["python", "/scraper/browserscraper.py"]
If I run those instructions in the Dockerfile from an interactive terminal, I have no problems.
It either has to do with the user being root running the script via the Dockerfile or something about it missing a screen for output because I'm not actually SSH'ed in like I am running it from the command line with -it.
Any ideas?

Related

Install docker desktop but when I run docker command it gives the error: exec: "com.docker.cli": executable file not found in $PATH

I'm trying to run docker desktop on my
ubuntu-22.04 but when I run any docker command in the terminal it gives the following error:
exec: "com.docker.cli": executable file not found in $PATH
Current PATH : /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/usr/local/bin
I noticed that my com.docker.cli file is colored red in the folder: usr/local/bin
see my image:
I also noticed that there is no docker directory in /usr/bin
Can anyone help me to resolve this?

azure devop selfhosted agent, newman command not recognized

Trying to run my postman collection in azure devops inside a self-hosted agent. When I try to run the command inside the agent "newman run postman_collection.json -e postman_environment.json -r cli,htmlextra" it's running fine. But when I run the same through a a command line script task in release pipeline it's throwing the error "newman is not recognized..". I also tried to have a npm task for newman installation i.e. "npm install -g newman" it's also throwing the erro "##[error]Unable to locate executable file: 'newman'. Please verify either the file path exists or the file can be found within a d...."
azure devop selfhosted agent, newman command not recognized
According to the error message "##[error]Unable to locate executable file: 'newman" when you using the npm install -g newman, you could try to add C:\Users\[BUILDSERVER-USERNAME]\AppData\Roaming\npm to the PATH variable for the [BUILDSERVER-USERNAME] user.
You could refer to this document How to fix the Newman task for Team Foundation Server silently failing for some more details.
Besides, when we use command line to install the newman, it will take a few minutes to install it, so we need to wait for a few minutes before we using the command line:
"newman run postman_collection.json -e postman_environment.json -r cli,htmlextra"
You could add powershell task to sleep a few minutes:
echo "Sleeping for 10 mins..."
Start-Sleep -s 600

Modify a line before starting the container

I used the following command to build a docker image
docker build -t shantanuo/mydash .
And the dockerfile is:
FROM continuumio/miniconda3
EXPOSE 8050
RUN cd /tmp/
RUN apt-get update
RUN apt-get install --yes git zip vim
RUN git clone https://github.com/kanishkan91/SuperTrendfor50Stocks.git
RUN pip install -r SuperTrendfor50Stocks/requirements.txt
WORKDIR SuperTrendfor50Stocks/
I can start the container, modify the application file and then start the app.
Step 1:
docker run -p 8050:8050 -it shantanuo/mydash bash
Step 2:
vi application.py
Change the last line
application.run_server(debug=True)
application.run(host='0.0.0.0')
Step 3:
python application.py
Can I avoid these 3 steps and merge everything in my dockerfile?
I do not think this is a good approach to change the line of code and then run the application manually, why not the code is self generic and modify the behaviour of application accordingly base on ENV.
You can try
# set default value accordingly
app.run(host=os.getenv('HOST', "127.0.0.1") , debug=os.getenv('DEBUG', False))
Now you can change that behaviour base on ENV.
web:
build: ./web
environment:
- HOST=0.0.0.0
- DEBUG=True
or
docker run -p 8050:8050 -e HOST="0.0.0.0" e DEBUG=True -it shantanuo/mydash
You also need to set CMD in the Dockerfile
CMD python app.py

docker file to run automation test in JS files

I am trying to create a docker file to run selenium tests for a java script based project. Below is my docker file so far:
#base image
FROM selenium/standalone-chrome
#access to the project within docker container - Bundle app source
COPY ./seleniumTest/project /app
# Install Node.js
RUN sudo apt-get update
RUN sudo apt-get install --yes curl
RUN curl --silent --location https://deb.nodesource.com/setup_8.x | sudo bash -
#binding
EXPOSE 8080
#Define runtime
ENTRYPOINT /app/login.test.js
while running with $ docker run -p 4000:80 lamgadekamal/dockertest
returns: Unable to find image 'lamkam/dockertest:latest' locally docker: Error response from daemon: manifest for lamkam/dockertest:latest not found. Could not figure out why am I getting this?
I suspect that you need to build your image first, since the image cannot be found.
Run this command from the same directory where your Dockerfile is located. This will build the image.
docker build -t lamgadekamal/dockertest .
You can then verify that the image exists by running docker images
EDIT: After looking at this again, it appears that you are trying to run the wrong image. You are trying to run lamgadekamal/dockertest, but you built the image with the tag lamkam/dockertest? Seems like you have a typo. I would suggest running docker images to see exactly what is there, but in all likelihood, you need to run lamkam/dockertest.
docker run -p 4000:80 lamkam/dockertest

Apache Tomcat 8 not starting within a docker container

I am experimenting with Docker and am very new to it. I am struck at a point for a long time and am not getting a way through and hence came up with this question here...
Problem Statement:
I am trying to create an image from a docker file containing Apache and lynx installation. Once done I am trying to access tomcat on 8080 of the container which is in turn forwarded to the 8082 of the host. But when running the image I never get tomcat started in the container.
The Docker file
FROM ubuntu:16.10
#Install Lynx
Run apt-get update
Run apt-get install -y lynx
#Install Curl
Run apt-get install -y curl
#Install tools: jdk
Run apt-get update
Run apt-get install -y openjdk-8-jdk wget
#Install apache tomcat
Run groupadd tomcat
Run useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
Run cd /tmp
Run curl -O http://apache.mirrors.ionfish.org/tomcat/tomcat- 8/v8.5.12/bin/apache-tomcat-8.5.12.tar.gz
Run mkdir /opt/tomcat
Run tar xzvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1
Run cd /opt/tomcat
Run chgrp -R tomcat /opt/tomcat
Run chmod -R g+r /opt/tomcat/conf
Run chmod g+x /opt/tomcat/conf
Run chown -R tomcat /opt/tomcat/webapps /opt/tomcat/work /opt/tomcat/temp opt/tomcat/logs
Run cd /opt/tomcat/bin
Expose 8080
CMD /opt/tomcat/bin/catalina.sh run && tail -f /opt/tomcat/logs/catalina.out
When the image is built I tried running the container by the two below methods
docker run -d -p 8082:8080 imageid tail -f /dev/null
While using the above, container is running but tomcat is not started inside the container and hence not accessible from localhost:8082. Also I do not see anything if I perform docker logs longcontainerid
docker run -d -p 8082:8080 imageid /path/to/catalina.sh start tail -f /dev/null
I see tomcat started when I do docker logs longconatainrid
While using the above the container is started and stopped immediately and is not running as I can see from docker ps and hence again not accessible from localhost:8082.
Can anyone please tell me where I am going wrong?
P.s. I searched a lot on the internet but could not get the thing right. Might be there is some concept that i am not getting clearly.
Looking at the docker run command documentation, the doc states that any command passed to the run will override the original CMD in your Dockerfile:
As the operator (the person running a container from the image), you can override that CMD instruction just by specifying a new COMMAND
1/ Then when you run:
docker run -d -p 8082:8080 imageid tail -f /dev/null
The container is run with COMMAND tail -f /dev/null, the original command starting tomcat is overridden.
To resolve your problem, try to run:
docker run -d -p 8082:8080 imageid
and
docker log -f containerId
To see if tomcat is correctly started.
2/ You should not use the start argument with catalina.sh. Have a look at this official tomcat Dokerfile, the team uses :
CMD ["catalina.sh", "run"]
to start tomcat (when you use start, docker ends container at the end of the shell script and tomcat will start but not maintain a running process).
3/ Finally, why don't you use tomcat official image to build your container? You could just use the :
FROM tomcat:latest
directive at the beginning of your Dockerfile, and add you required elements (new files, webapps war, settings) to the docker image.