Docker-compose mount test results inside a local volume - docker

I have python tests that generate the results of the tests as HTML and XML files. When I run docker-compose, I want to find these results and mount them in a local volume.
docker-compose.yml
version "3.9"
services:
tests:
build: .
image: test-image
volumes:
- myLocalVolumes:/my/url/to/tests/results
volumes:
myLocalVolumes
I am using a MacBook. Any tips on how to find the URL of these test results.
I think it has to be taken from inside the container or stored somewhere in the computer.

if your goal is to save test results. first find where the results are saved in the container. if your script/code write results to folder called results in the same working directory
you should first find the working dir
you can find it in the Dockerfile
example:
WORKDIR /project
then mount the results directory to the docker volume
version "3.9"
services:
tests:
build: .
image: test-image
volumes:
- myLocalVolumes:/project/results
volumes:
myLocalVolumes
you will find volume in the path /var/lib/docker/volumes/myLocalVolumes
or in more simple way you can mount to a folder in the host machine
version "3.9"
services:
tests:
build: .
image: test-image
volumes:
- ./results:/project/results
if your script/code generates individual files with different unique names it's better to modify the code to put results into a directory so you can mount them easily.

The solution is there is a folder named results inside the project. That folder contains all the results of the tests as HTML and XML files. To mount that data, we will do: myLocalVolumes:/results.
The complete docker-compose.yml will be
version "3.9"
services:
tests:
build: .
image: test-image
volumes:
- myLocalVolumes:/results
volumes:
myLocalVolumes

Related

Docker - store output on local filesystem

I've got a docker-container that's running a program which outputs something. I want that something to be stored on my local file system, not in a volume. Bind mounts are what I need.
I have a single folder called oniongen and this is where I want the output.
My compose file looks like this:
version: '3'
services:
oniongen:
image: nwtgck/mkp224o
volumes:
- ./oniongen:/gen
command: >
sh -c "mkp224o abcd -d gen"
However, the outputs never reach my local file system.
I've tried
volumes:
oniongen:
driver: local
and this incarnation just in case
volumes:
oniongen:
and also specifying bind under volume type
services:
oniongen:
image: nwtgck/mkp224o
volumes:
- type: bind
source: ./oniongen
target: /gen
volumes:
oniongen:
I've tried other suggestions too and read the docs, but can't seem to get the output stored locally.
If I sh into the container I can see the gen folder and the files in it.
How do I get these files to be stored on my local system?
You're really over-complicating it, just mount a local folder as your volume:
services:
oniongen:
image: nwtgck/mkp224o
volumes:
- ./oniongen:/gen
No need for the volumes top level declaration either.
This will result in everything the container puts in its /gen folder appearing in the host's ./oniongen folder and vice-versa.

Including Cypress config file into docker-compose

I am following this article to run Cypress test with Docker.
I encountered issue where I need cypress.json file to be included in docker-compose.yaml. Here is example of my docker-compose.yamlfile looks like
version: '3.3'
services:
cypress:
image: "cypress/included:7.7.0"
enviroment:
- HTTP_PROXY=somekind_url
working_dir: location of cypress files
volumes:
- ./:/cypress
command: [-b, chrome]
My question is how to tell in docker-compose.yaml to grab my cypress.json that is located in root project directory?
You can see how in https://github.com/cypress-io/cypress-example-docker-compose-included/blob/master/docker-compose.yml
volumes:
- ./cypress:/cypress
- ./cypress.json:/cypress.json
./cypress.json it's your local file, and /cypress.json it's the file into the container.

docker compose mount local drive

I am using owncloud docker image to create my owncloud. The problem is it's storing the data inside the docker image. However, I want one of my driver ( I am using windows) to be used as data files.
volumes:
files:
driver: local
services:
owncloud:
volumes:
- files:/mnt/data
This is what part of the docker-compose files looks like, I tried changing files:/mnt/data to .:/mnt/data. However, I started getting error when I tried to run the docker-compose.
The right way is to use double quotes to expand . as the current directory:
version: '3'
services:
nginx:
image: nginx
volumes:
- ".:/path/inside/container/"

Docker / Docker-compose volume fill & share issue

I have a few questions about Docker volumes. I have installed Docker and docker-compose on a fresh host running debian stretch. I managed to get a docker-compose file running for a simple nginx/php-fpm project, both containers mounted on the directory containing the source code. I wanted to try to create a single volume that would be shared across my containers but I have a few issue, and my understanding of the official documentation is not helping.
So this is an idea of what I'm trying to achieve :
Question 1 : Trying to create a volume from a dockerfile on a directory mounted from host
docker-compose.yml :
version: '3'
services:
php:
build:
context: .
dockerfile: php.dockerfile
volumes:
- ./host-project-directory:/project
php.dockerfile :
FROM php:7-fpm
VOLUME project
from my understanding, when running docker-compose we should have a volume created on host containing all files from /project from container. And /project from container should contain all files from ./host-project-directory from host.
If I ls the content of /project on container I can see the files from host, but using docker volume list, there are no volumes created on host, why ?
Question 2 : How to populate and use this volume from another container ?
version: '3'
services:
php:
build:
context: .
dockerfile: php.dockerfile
volumes:
- named-volume:/project
web:
image: nginx
links:
- php
volumes:
- named-volume:/project
volumes:
named-volume:
This should create a volume called 'named-volume' and bind it to /project directories on both containers php and web.
Now, how to populate this volume with content from ./host-project-directory ?
I've tried adding a dockerfile like
ADD ./host-project-directory /project
But nothing changed and the volume remained empty.
I'm sorry if this is due to my lack of experience using Docker but I can't figure out how to make this simple thing work.
Thank you for your time !
For the first question, I try a simple docker file like this:
FROM php:7-fpm
COPY ./project /project
And a docker-compose like this:
version: '3'
services:
php:
build: .
volumes:
- named-volume:/project
web:
image: nginx
links:
- php
volumes:
- named-volume:/project
volumes:
named-volume:
Since you create the volume on docker-compose you don't need to create that in the Dockerfile.
Running docker volume list, I'm able to see the volume created with a local driver. Making ls inside the folder I'm also able to see the file. It's important to note, that the file present in you local directory it's not the same that the file inside the container. So if you edit the files in the host this will not change the files in container. That's because you have your volume created in another path, probably at: /var/lib/docker/volumes/...
This happens because you map the volume to the path, but you not specifies where you want the volume. To do that just make your docker-compose like this:
version: '3'
services:
php:
build: .
volumes:
- ./project:/project
web:
image: nginx
links:
- php
volumes:
- ./project:/project
Making this I'm still able to see the volume with the volume list command but without a name.
So I don't know why you are not able to see the volume in the list.
For question 2:
Doing the example above I have the files inside the container that exists in my local "project" folder.
Please check that the path to the local folder is correct.
A bind mount is not the same thing as a volume. You're defining a named volume here, but wanting the functionality of a bind mount.
Try this
version: '3'
services:
php:
build:
context: .
dockerfile: php.dockerfile
volumes:
- ./host-project-directory:/project
web:
image: nginx
links:
- php
volumes:
- ./host-project-directory:/project

volume with files in Dockerfile, available in other containers with docker-compose

I have one Dockerfile which more or less does:
VOLUME /files
RUN echo "foo" > /files/x
And then I have a docker-compose.yml which more or less is:
version: '3'
services:
files:
volumes:
- files:/files
other_service:
volumes:
- files:/files
depends_on:
- files
volumes:
files:
The problem is that the /files gets overwritten by the docker-compose (and gets empty).
In the past (with docker-compose v2) I think that I used something like this:
version: '2'
services:
files:
other_service:
volumes_from:
- files
depends_on:
- files
worked
How can I do it in version 3?
(Declaring a volume in the Dockerfile, putting some files inside this volume and then, have these files available in other containers (with docker-compose)

Resources