Including Cypress config file into docker-compose - docker

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.

Related

Docker container not picking up CSS file

I have a docker-compose file as follows:
version: '3.8'
services:
signup:
container_name: signup
build: .
ports:
- "88:80"
image: sgc-signup:Dockerfile
networks:
- test
restart: always
networks:
test:
external:
name: test
And a docker file of:
FROM php:7.2-apache
COPY src/ /var/www/html/
The working directory for this container is:
sgc-signup
src
footer.php
functions.php
index.php
navbar.php
styling.css
docker-compose.yml
Dockerfile
The console when i run the container locally returns the following error regarding styling .css:
Failed to load resource: net::ERR_CONNECTION_REFUSED
Almost identical code has worked in another container for signin.
I have tried clearing the cache as well as docker-compose up --build and a couple of similar solutions found on stack overflow with no joy so far.

Docker-compose mount test results inside a local volume

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

How do I create this using Docker

Download the repository to your local machine and unzip the directory. Enter the directory (you may rename the directory first) on command line environment, then use the following command to download the rails docker image and to build.
The repository file is been downloaded and unzipped it. What should I do
docker-compose run web rails new . --force --no-deps --database=postgresql
docker-compose build
ERROR:
Can't find a suitable configuration file in this directory or any
parent. Are you in the right directory?
Supported filenames: docker-compose.yml, docker-compose.yaml
You need to define docker-compose.yml file or docker-compose.yaml. Accordingly to documentation:
Using Compose is basically a three-step process:
1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
2. Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
3. Run docker-compose up and Compose starts and runs your entire app.
A docker-compose.yml looks like this:
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
- logvolume01:/var/log
links:
- redis
redis:
image: redis
volumes:
logvolume01: {}
More on official website

Trying to connect"neither an image nor a build context specified."

Running docker-compose commands like build and up works.
However when I try to connect docker with VS Code I get this error:
The Compose file is invalid because:
Service your-service-name-here has neither an image nor a build context specified. At least one must be provided.
This is the compose file:
version: '3'
services:
db:
image: postgres
ports:
- "5432:5432"
web:
build: .
command: bin/rails server --port 3000 --binding 0.0.0.0
ports:
- "3000:3000"
links:
- db
volumes:
- .:/myapp
Look at your devcontainer.json in the .devcontainer folder. Mine had an autogenerated docker-compose.yml from a previous experiment and it was a partially-filled template which could not work, hence the error message.
Found this by looking carefully at the command VSCode was trying to execute (the -f argument).
Cleaning up the .json config file solved the issue.
I very probably that your should be specific build context
build:
context: . # if you stay on root project

Docker-compose volumes doesn't copy any files

I'm in Fedora 23 and i'm using docker-compose to build two containers: app and db.
I want to use that docker as my dev env, but have to execute docker-compose build and up every time i change the code isn't nice. So i was searching and tried the "volumes" option but my code doesn't get copied to docker.
When i run docker-build, a "RUN ls" command doesn't list the "app" folder or any files of it.
Obs.: in the root folder I have: docker-compose.yml, .gitignore, app (folder), db (folder)
Obs¹.: If I remove the volumes and working_dir options and instead I use a "COPY . /app" command inside the app/Dockerfile it works and my app is running, but I want it to sync my code.
Anyone know how to make it work?
My docker-compose file is:
version: '2'
services:
app:
build: ./app
ports:
- "3000:3000"
depends_on:
- db
environment:
- DATABASE_HOST=db
- DATABASE_USER=myuser
- DATABASE_PASSWORD=mypass
- DATABASE_NAME=dbusuarios
- PORT=3000
volumes:
- ./app:/app
working_dir: /app
db:
build: ./db
environment:
- MYSQL_ROOT_PASSWORD=123
- MYSQL_DATABASE=dbusuarios
- MYSQL_USER=myuser
- MYSQL_PASSWORD=mypass
Here you can see my app container Dockerfile:
https://gist.github.com/jradesenv/d3b5c09f2fcf3a41f392d665e4ca0fb9
Heres the output of the RUN ls command inside Dockerfile:
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
A volume is mounted in a container. The Dockerfile is used to create the image, and that image is used to make the container. What that means is a RUN ls inside your Dockerfile will show the filesystem before the volume is mounted. If you need these files to be part of the image for your build to complete, they shouldn't be in the volume and you'll need to copy them with the COPY command as you've described. If you simply want evidence that these files are mounted inside your running container, run a
docker exec $container_name ls -l /
Where $container_name will be something like ${folder_name}_app_1, which you'll see in a docker ps.
Two things, have you tried version: '3' version two seems to be outdated. Also try putting the working_dir into the Dockerfile rather than the docker-compose. Maybe it's not supported in version 2?
This is a recent docker-compose I have used with volumes and workdirs in the respective Dockerfiles:
version: '3'
services:
frontend:
build:
context: ./frontend
dockerfile: Dockerfile.dev
ports:
- 3001:3001
volumes:
- ./frontend:/app
networks:
- frontend
backend:
build: .
ports:
- 3000:3000
volumes:
- .:/app
networks:
- frontend
- backend
depends_on:
- "mongo"
mongo:
image: mongo
volumes:
- ./data/db:/data/db
ports:
- 27017:27017
networks:
- backend
networks:
frontend:
backend:
You can extend or override docker compose configuration. Please follow for more info: https://docs.docker.com/compose/extends/
I had this same issue in Windows!
volumes:
- ./src/:/var/www/html
In windows ./src/ this syntax might not work in regular command prompt, so use powershell instead and then run docker-compose up -d.
it should work if it's a mounting issue.

Resources