Docker-compose mount directory - docker-compose

ok this is driving me nuts already. What I just want to do is launch php:5.6-apache image and mount my ./web to /var/www/html by having the following docker-compose.yml file:
version: '2'
services:
apache:
image: php:5.6-apache
volumes:
- ./web:/var/www/html
ports:
- 8081:80
Launching it with docker-compose up.
For some unknown reason this results in empty /var/www/html folder, although it should contain what I have in ./web.
Or I am doing it wrong?

Well, it turned out that for some reason windows firewall prevented folder sharing. It seems that it was because DockerNat network was listed among Public networks, so I had to run the following commands in elevated power shell:
$Profile = Get-NetConnectionProfile -InterfaceAlias "vEthernet (DockerNAT)"
$Profile.NetworkCategory = "Private"
Set-NetConnectionProfile -InputObject $Profile
Then I was able to enable drive sharing in docker settings and then mounted folders became filled with files.
[UPDATE 2018-05-03] There's a good gist that will put dockerNat network to private when you restart docker. All you have to do is modify MobyLinux.ps1 file located at C:\Program Files\Docker\Docker\resources by adding include at 86, function at 182-186 and modifying lines try/catch statement at 399-409 to include Set-Switch-Private function calls.

Related

VSCode-Docker Not Invoking "CMD"

TL;DR Image built by VSCode only executes the CMD command when I press the Run button in the Docker Desktop UI.
Hello Folks,
I'm playing around with a Drools image along with Docker Desktop and VSCode.
My devcontainer.json file looks like the following:
{
"name": "Existing Dockerfile",
"build": {
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerfile": "../Dockerfile"
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [8001,8080]
}
My Dockerfile is minimalist and looks like the following:
FROM quay.io/kiegroup/business-central-workbench:latest
And my compose.yaml file looks like so:
services:
app:
entrypoint:
- sleep
- infinity
image: docker/dev-environments-default:stable-1
init: true
volumes:
- type: bind
source: /var/run/docker.sock
target: /var/run/docker.sock
The issue is that when VSCode sends the image to Docker Desktop, the
CMD ["./start_business-central-wb.sh"] found in the parent image does not seem to be getting set off as seen in the logs
However, when I click "Run" the command gets kicked off after spawning a new instance
What concept am I missing as to why the Docker image doesn't immediately begin running when VSCode sends it to Docker Desktop? I'm super inexperienced with both techs.
Any help is greatly appreciated.

how to set an environment variable when run - az container app compose create

It seems when my docker compose yml is run via "az containerapp compose create", environment variables are not picked up. Is there a way I can set an env variable so the command picks it up?
I'm seeing this error:
ERROR: The following field(s) are either invalid or missing. Invalid value: "${DOCKER_REGISTRY-}/sample-blazorapp": could not parse reference: ${DOCKER_REGISTRY-}/sample-blazorapp: template.containers.blazorapp.image.
I have set the variable with: export DOCKER_REGISTRY="myregistry"
And when I echo $DOCKER_REGISTRY, the value is returned. So in the bash session it is set (I tried powershell first, I thought that was the issue because $(envvar-) is bash syntax, however the error is the same.)
This is what I have in my compose file (alignment is correct in the file):
blazorapp:
container_name: "blazorapp"
image: ${DOCKER_REGISTRY-}sample-blazorapp
build:
context: .
dockerfile: BlazorApp/BlazorApp/Dockerfile
depends_on:
- redis
ports:
- "55000:443"
If I explicitly set the image name, i.e. not use an env var, then it works. i.e. this change to the image line works:
image: myregistry/sample-blazorapp
I also tried adding the forward slash, this makes no difference (as expected, it works fine without the slash when running docker compose up).
I can set it explicitly but that would be annoying. I feel like I'm missing something. Any help or guidance is greatly appreciated :)
If the image is defined like this into you docker compose file:
image: ${DOCKER_REGISTRY-}sample-blazorapp
then you must export using a slash at the end of the value:
export DOCKER_REGISTRY="myregistry/"
I discovered the issue, I was missing a colon.
Does not work (produces the error described in the question):
image: ${DOCKER_REGISTRY-}sample-blazorapp
Also does not work:
image: ${DOCKER_REGISTRY-mydefault}sample-blazorapp
Add the magic : in and it works:
image: ${DOCKER_REGISTRY:-}sample-blazorapp
Also works:
image: ${DOCKER_REGISTRY:-mydefault}sample-blazorapp

Docker-compose volumes to map to external usb drive

I would like to map an external usb drive in my docker-compose.yml I used the following:
volumes:
external: true
#- bitcoin-data:/data original line commented out to attempt next line
- bitcoin-data:/run/media/directory name/external drive name/docker-base
However when running docker-compose up I receive the following:
ERROR: yaml.parser.ParserError: while parsing a block mapping
in "./docker-compose.yml", line 5, column 5
expected <block end>, but found '<scalar>'
in "./docker-compose.yml", line 16, column 8
Line 5 refers to the image and Line 16 refers to the external drive I am
attempting to save data destination.
You cannot add a list in a yaml file just after a variable, that's why you have this error. If you want to add the external parameter, you will have to put the volumes's path into you container section, and the external setting into the volumes section, like:
services:
yourcontainer:
[...]
volumes:
- bitcoin-data:/run/media/directory name/external drive name/docker-base
volumes:
bitcoin-data:
external: true

Docker COPY error when copying files from host to container

In the following Dockerfile I'm trying to copy a jar file from a location on the host into the container, but seems Docker does not like it as I guess I'm missing something. Here is my Dockerfile:
FROM anapsix/alpine-java:jdk8
MAINTAINER joesan
ENV SBT_VERSION 0.13.15
ENV CHECKSUM 18b106d09b2874f2a538c6e1f6b20c565885b2a8051428bd6d630fb92c1c0f96
ENV APP_NAME my-app
ENV PROJECT_HOME /opt/apps
RUN mkdir -p $PROJECT_HOME/$APP_NAME
# Copy the jar file
COPY ./target/scala-*/my-app-*.jar $PROJECT_HOME/$APP_NAME
# Copy the database file
COPY .my-db.mv.db $PROJECT_HOME/$APP_NAME
# Run the application
CMD ["$PROJECT_HOME/$APP_NAME java -Denv=dev -jar my-app-*.jar"]
In my build pipeline, I could see the following error message:
Step 8/10 : COPY ./target/scala-*/my-app-*.jar $PROJECT_HOME/$APP_NAME
COPY failed: no source files were specified
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 4a240742a379 Less than a second ago 171MB
anapsix/alpine-java jdk8 ed55c27d366d 3 years ago 171MB
Error response from daemon: No such image: [secure]
Pushing image [secure] to repository hub.docker.com
The push refers to repository [docker.io/[secure]/my-app]
An image does not exist locally with the tag: [secure]/my-app
What is that I'm missing and how could I debug this? I mean I could add some echo statements to print out the path, but I'm not sure why I face this error!
This is probably because the target folder is not in "./" folder. which can be because it's ignored by .dockerignore file or the build context is not pointing to the parent folder of the target folder.
In case you are not familiar with build context, it's explained here

Cypress and Docker - Can't run because no spec files were found

I'm trying to run cypress tests inside a docker container. I've simplified my setup so I can just try to get a simple container instance running and a few tests executed.
I'm using docker-compose
version: '2.1'
services:
e2e:
image: test/e2e:v1
command: ["./node_modules/.bin/cypress", "run", "--spec", "integration/mobile/all.js"]
build:
context: .
dockerfile: Dockerfile-cypress
container_name: cypress
network_mode: host
and my Dokerfile-cypress
FROM cypress/browsers:chrome69
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
RUN npm install cypress#3.1.0
COPY cypress /usr/src/app/cypress
COPY cypress.json /usr/src/app/cypress
RUN ./node_modules/.bin/cypress verify
when I run docker-compose up after I build my image I see
cypress | name_to_handle_at on /dev: Operation not permitted
cypress | Can't run because no spec files were found.
cypress |
cypress | We searched for any files matching this glob pattern:
cypress |
cypress | integration/mobile/all-control.js
cypress exited with code 1
I've verified that my cypress files and folders have been copied over and I can verify that my test files exist. I've been stuck on this for a while and i'm unsure what to do besides giving up.
Any guidance appreciated.
Turns out cypress automatically checks for /cypress/integration folder. Moving all my cypress files inside this folder got it working.
The problem: No cypress specs files were found on your automation suite.
Solution: Cypress Test files are located in cypress/integration by default, but can be configured to another directory.
In this folder insert your suites per section:
for example:
- cypress/integration/billing-scenarios-suite
- cypress/integration/user-management-suite
- cypress/integration/proccesses-and-handlers-suite
I assume that these suite directories contains sub directories (which represents some micro logic) ,therefore you need to run it recursively to gather all files:
cypress run --spec \
cypress/integration/<your-suite>/**/* , \
cypress/integration/<your-suite>/**/**/*
If you run in cypress on docker verify that cypress volume contains the tests and mapped and mounted in container on volume section (on Dockerfile / docker-compose.yml file) and run it properly:
docker exec -it <container-id> cypress run --spec \
cypress/integration/<your-suite>/**/* , \
cypress/integration/<your-suite>/**/**/*
I noticed that if you CLICK AND DRAG file method to get file path in VSC, then it generates path with SMALL c-drive letter and this causes error: "Can't run because no spec files were found. + We searched for specs matching this glob pattern:"
e.g. by click and drag I get:
cypress run --spec c:\Users\dmitr\Desktop\cno-dma-replica-for-cy-test\cypress\integration\dma-playground.spec.js
Notice SMALL c, in above.
BUT if I use right click 'get path', I get BIG C, and it works for some reason:
cypress run --spec C:\Users\dmitr\Desktop\cno-dma-replica-for-cy-test\cypress\integration\dma-playground.spec.js
and this causes it to work.
Its strange I know, but there you go.
but if you just use: