How to copy files from docker container to host using docker-compose in docker-machine - selenium

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/

Related

Slow apache + mysql inside of Docker

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!

Appium - Register many devices to selenium grid docker

I'm studying to use docker.
1. I connect 2 real devices to my computer.
2. I have this docker-compose file:
# Note: It requires docker-compose 1.13.0
#
# Usage: docker-compose up -d
version: "2.2"
services:
# Selenium hub
selenium_hub:
image: selenium/hub:3.14.0-curium
ports:
- 4444:4444
# Using Appium Docker Android
real_device:
image: appium/appium
depends_on:
- selenium_hub
network_mode: "service:selenium_hub"
privileged: true
volumes:
- /dev/bus/usb:/dev/bus/usb
- ~/.android:/root/.android
- ./appFolder:/root/tmp
environment:
- CONNECT_TO_GRID=true
- SELENIUM_HOST=selenium_hub
I start docker like this, it shows there are 2 devices:
console log
But when I open my browser, there is one device only:
Browser
How can I connect 2 of my devices to grid docker?
Thanks
In order to run Appium in grid you need to setup config file. Check out this documentation here and here to know how.

Docker : image build failed

when building docker apache image, the building fail in this step :
Step n/m : COPY httpd-foreground /usr/local/bin/
ERROR: Service 'apache' failed to build: COPY failed: stat
/var/lib/docker/tmp/docker-builder511740141/httpd-foreground: no such
file or directory
this is my docker_compose.yml file
version: '3'
services:
mysql:
image: mysql:5.7
container_name: mysql_octopus_dev
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: app
MYSQL_USER: root
MYSQL_PASSWORD: root
apache:
build: .
container_name: apache_octopus_dev
volumes:
- .:/var/www/html/
ports:
- "8000:80"
depends_on:
- mysql
this is my docker file
FROM debian:jessie-backports
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
#RUN groupadd -r www-data && useradd -r --create-home -g www-data www-data
...
COPY httpd-foreground /usr/local/bin/
EXPOSE 80
CMD ["httpd-foreground"]
any help please?
Paths in a Dockerfile are always relative to the the context directory. The context directory is the positional argument passed to docker build (often .).
I should place the httpd-foreground file in the same folder of dockerfile.
From : https://github.com/docker/for-linux/issues/90

Unable to copy file from docker-compose mount to host

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

Update shared volume from data container

Hi guys i'm in this situation, i'd like to deploy the changes in my source code by rebuilding the data container which contains a COPY command for transfer the source in the volume. However when i rebuild the data image and re-run docker-compose i stuck with the old code and the only way to update everything is to remove the webroot volume and recreate it.
Where is the mistake??
server:
build: ./docker/apache
image: server:1.3.16
restart: always
links:
- fpm
ports:
- 80:80 # HTTP
- 443:443 # HTTPS
volumes:
- webroot:/var/www/html:ro
fpm:
build: ./docker/php
image: fpm:1.0
restart: always
links:
- database
volumes:
- webroot:/var/www/html
data:
build:
context: .
dockerfile: dataDockerFile
image: smanapp/data:1.0.0
volumes:
- webroot:/var/www/html
volumes:
webroot:
The named volume webroot is meant to persist data across container restart/rebuilds. The only time the data in the volume is updated from an image is when the volume is created, and the contents of the directory in the image are copied in.
It looks like you mean to use volumes_from which is how you get container to mount volumes defined on data. This is the original "data container" method of sharing data that volumes were designed to replace.
version: "2.1"
services:
server:
image: busybox
volumes_from:
- data
command: ls -l /var/www/html
fpm:
image: busybox
volumes_from:
- data
command: ls -l /var/www/html
data:
build: .
image: dply/data
volumes:
- /var/www/html
Note that this has been replaced in version 3 of the compose file so you may need to stick with recreating the volume if you want to use newer features.