I am unable to copy a file generated by my Selenium tests in a folder inside docker container mounted to host machine.
Here is how my compose file look like
selenium:
image: 'selenium/standalone-chrome'
expose:
- "4444"
tests:
build:
context: ./tests
dockerfile: Dockerfile
depends_on:
- selenium
- web
volumes:
- /testResultsReport:/testResultsReport
This is how my directory structure looks like.
\
- docker-compose.yml
- build scripts
- tests
- testResultsReport
- Test scripts
Name of the file generated inside testResultsReport folder when running docker-compose is TestResultsReport.HTML
As my tests are running inside selenium server on port 4444, should I mount my volume there? I tried doing that to but still not getting my html file copied to host machine?
I confirmed that my html file is generated when i run my tests outside compose.
I also tried ./testResultsReport however it added a folder in root with name of testResultsReport and did nothing. So I used ./tests/testResultsReport but still not getting file.
Worked by using right folder and absolute path. Thanks #chrisz
selenium:
image: 'selenium/standalone-chrome'
expose:
- "4444"
tests:
build:
context: ./tests
dockerfile: Dockerfile
depends_on:
- selenium
- web
volumes:
- ./tests/testResultsReport:/tests/testResultsReport
Related
I've configured IntelliJ to use python via a stack I've defined in docker-compose. I'm configured my project to execute my pytest via docker-compose so that I can use the debugger. However, I've discovered that after the initial run, when I change my code and re-run my tests, pytest is not seeing my changes, but rather executing a cached version of the code.
The only way I've discovered to get around this is to invoke the File menu option Invalidate Caches and Restart. This is annoying.
This my compose file:
networks:
app: {}
services:
item-set-definitions:
build:
context: /Users/kudrykma/ghoildex/kudrykma/analytics/sa-item-set-definitions
target: build
command:
- /bin/bash
image: item-sets:test
networks:
app: {}
volumes:
- source: /Users/kudrykma/ghoildex/kudrykma/analytics/sa-item-set-definitions
target: /project
type: bind
version: '3.9'
In the pytest Run configuration I've tried adding -force-recreate option in the docker-compose Command and options field but IntelliJ won't recognize it.
Does anyone know how I can configure IntelliJ to not cache any of my source file so that pytest will see my changed code?
Thank you
I use Selenium IDE for file downloading test. The test works correctly when I ran it locally(downloads page opens and the list contains file that I downloaded), but it doesn't work in robcherry/docker-chromedriver docker. In the test I open chrome://downloads/ page after file downloading and this list is empty in docker.
I've added downloading path to a docker-compose file, but it doesn't help.
Here my docker-compose file
version: '3'
services:
chromedriver:
image: robcherry/docker-chromedriver
privileged: true
restart: always
environment:
- TZ=Europe/Moscow
- CHROMEDRIVER_WHITELISTED_IPS=''
volumes:
- './module-selenium:/selenium'
- './module-selenium/Downloads:/tmp/downloads'
selenium-side-runner:
image: bolotoff/selenium:v11
volumes:
- './module-selenium:/sides'
- './out:/root/out'
I have a problem with performance of my Dockerized app. I have Windows OS. When I run my app using xampp it takes the page ~1 second to load. When I run it inside of Docker it takes ~5 seconds for the page to load. I tried:
1. Docker
2. Docker Toolbox (which creates VirtualBox linux machine and runs Docker inside of it)
Result are the same. Here is my Docker-compose file:
version: '3'
networks:
default:
driver: bridge
services:
webserver:
build: ./docker/webserver
image: yiisoftware/yii2-php:7.3-apache
ports:
- "80:80"
- "443:443"
networks:
- default
volumes:
- /aaa:/var/www/html
links:
- db:mysql
environment:
MYSQL_PORT_3306_TCP_ADDR: db
db:
image: mysql:5.7
ports:
- "3306:3306"
networks:
- default
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=pass
- MYSQL_DATABASE=aaa
Can anybody give me a hint how to fix this? Or this is a regular behavior on Windows pc? Thank you.
The reason was that there was no APCU inside of the container. And without the cache code was 20 times slowlier. Always check if you need all necessary libs and modules inside of your containers!
I have reports generated in gradle container for my selenium tests, I am trying to copy the files from docker container to local host. As a work around, I have used docker cp to copy files from container to my local and it works. How to achieve it with docker-compose volumes.
Below is my docker-compose.yml
version: "3 "
services:
selenium-hub:
image: selenium/hub
container_name: selenium-hub_compose
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome-debug
container_name: selenium-chrome
depends_on:
- selenium-hub
ports:
- "5900"
environment:
- http_proxy=http://x.x.x.x:83
- https_proxy=http://x.x.x.x:83
- HUB_HOST=selenium-hub
- HUB_PORT=4444
gradle:
image: gradle:jdk8
container_name: selenium-gradle
build:
context: .
dockerfile: dockerfile
I run the command docker-compose up -> it runs the selenium tests and generates the report in the container.
Can anyone help on this?
The normal way to pass data from container to host is using docker volumes.
In short you specify a host directory and map it to the directory inside container. And that directory should be used to save your test reports
services:
selenium-hub:
image: selenium/hub
container_name: selenium-hub_compose
ports:
- "4444:4444"
volumes:
- ./path/to/report/folder:/host/reports
See docker documentation
https://docs.docker.com/compose/compose-file/#/volumes-volumedriver
Similar question:
How do I mount a host directory as a volume in docker compose
Power off the machine in Virtual box -> Change the Advanced settings in Virtual box
Goto Shared Folders in Virtual box
Give Path :: C:\DockerResults : Give a logical name for the Folder name
Restart the machine in DockerTerminal with the below command
docker-machine restart default
After machine is started open the Virtual box
Create a directory in the Virtual machine : sudo mkdir /Results
Mount the directory to the local windows machine by executing the below command in virtual box:
Sudo mount –t vboxsf DockerResults /Results
Add volumes as below in docker-compose file
volumes:
- /DockerResults:/home/Reports/
I'm trying to find a more DRY way to use docker-compose env.
docker-compose-base.yml
base:
image: reactjs_web
volumes:
- src:/reactjs/src
- bin/server:/reactjs/bin/server
- config:/reactjs/config
docker-compose-prod.yml
svr:
extends:
file: docker-compose-base.yml
service: base
command: npm run prod:deploy
ports:
- "8081:8081"
environment:
NODE_ENV: production
PORT: "8081"
CLTPORT: "8082"
clt:
extends:
file: docker-compose-base.yml
service: base
command: npm run prod:deploy:clientside
ports:
- "8082:8082"
environment:
NODE_ENV: production
PORT: "8082"
The ports and the env port are equals
Is there a way to reference the clt port to the svr container ?
Docker Environment File
Use a .env file and reference it in both containers. This will ensure you only need to store these settings in a single location.
Compose supports declaring default environment variables in an environment file named .env placed in the folder docker-compose command is executed from (current working directory).
Compose expects each line in an env file to be in VAR=VAL format. Lines beginning with # (i.e. comments) are ignored, as are blank lines.
Compose File Integration:
env_file: .env
env_file:
- ./common.env
- ./apps/web.env
- /opt/secrets.env
Docker Compose File Reference - env_file
Docker Compose Environment File Documentation
You can use environment variable inside docker-compose.
svr:
extends:
file: docker-compose-base.yml
service: base
command: npm run prod:deploy
ports:
- ${CLTPORT}:${PORT}
environment:
NODE_ENV: production
clt:
extends:
file: docker-compose-base.yml
service: base
command: npm run prod:deploy:clientside
ports:
- ${CLTPORT2}:${PORT2}
environment:
NODE_ENV: production
run docker-compose like:
CLTPORT=8082 PORT=8081 CLTPORT2=8081 PORT2=8082 docker-compose -f docker-compose-prod.yml up
Of course change your port variables as you need.
You can reference an environment variable to solve this
https://github.com/docker/compose/issues/1377