When running docker-compose remotely, an error occurs with mounting volumes - docker

I am trying to run a project on docker-compose via a remote server. Everything works, but as soon as I add the item about mounting the volume, it gives an error:
Error response from daemon: invalid mount config for type "bind": invalid mount path: 'C:/Users/user/Projects/my-raspberry-test' mount path must be absolute
To run I use tools from PhpStorm.
The docker-compose.yml file itself looks like this:
version: "3"
services:
php:
image: php:cli
volumes:
- ./:/var/www/html/
working_dir: /var/www/html/
ports:
- 80:80
command: php -S 0.0.0.0:80
I checked by ssh:
Daemon is running,
Docker works (on a similar Dockerfile with the same tasks),
Docker-compose works (on the same file).
Also checked docker remote run using phpstorm and file:
FROM php:cli
COPY . /var/www/html/
WORKDIR /var/www/html/
CMD php -S 0.0.0.0:80
It didn’t give an error and it worked.
OS on devices:
PC: Windows 10
Server: Fedora Server
Without mounting the volume in docker-compose, everything starts. Maybe someone faced a similar problem?
php for an example.

The path must be absolute for the remote host and the project data itself must be loaded there. That is, you need to upload the project to a remote host.
I corrected everything like this:
volumes:
- /home/peter-alexeev/my-test:/var/www/html/

Related

How to reference a WSL path in docker-compose, in Windows

I would like to be able to reference a Dockerfile which is inside of a WSL container, from docker-compose which is running on Windows
The docker-compose file is inside of \\wsl$$\Ubuntu-20.04\home\marvinirwin\WebstormProjects\epub-finder, and so is the Dockerfile its tryin gto reference
version: "3.9"
services:
server:
build: \\wsl$$\Ubuntu-20.04\home\marvinirwin\WebstormProjects\epub-finder\server.dev.Dockerfile
ports:
- "3001:3001"
With that confirmation, when I run docker-compose up it produces the following error
unable to prepare context: path "\\\\?\\\\\\wsl$\\Ubuntu-20.04\\home\\marvinirwin\\WebstormProjects\\epub-finder\\server
.dev.Dockerfile" not found
The file exists at the path provided. The error message suggests that the path has been escape incorrectly. I'm not sure what the question mark is doing.
I have tried using the relative path ./server.dev.Dockerfile, but the error message is identical.
I'm using docker desktop on Windows, and both docker WSL instances and the Ubuntu instance I'm using are all WSL version 2.
I've read that UNC paths don't work, so I symlinked my container, and am able to ls C:\\wsl\\home\\marvinirwin\\WebstormProjects\\epub-finder\\server.dev.Dockerfile successfully
However, the configuration build: C:\wsl\home\marvinirwin\WebstormProjects\epub-finder\server.dev.Dockerfile (The same path I was able to ls from in powershell)

Docker - all-spark-notebook Communications link failure

I'm new using docker and spark.
My docker-compose.yml file is
volumes:
shared-workspace:
services:
notebook:
image: docker.io/jupyter/all-spark-notebook:latest
build:
context: .
dockerfile: Dockerfile-jupyter-jars
ports:
- 8888:8888
volumes:
- shared-workspace:/opt/workspace
And the Dockerfile-jupyter-jars is:
FROM docker.io/jupyter/all-spark-notebook:latest
USER root
RUN wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.28/mysql-connector-java-8.0.28.jar
RUN mv mysql-connector-java-8.0.28.jar /usr/local/spark/jars/
USER jovyan
To it start up a run
docker-compose up --build
The server is up and running and I'm interested to use spark-sql, but it is throwing and error trying to connect to mysql server:
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
I can see the mysql-connector-java-8.0.28.jar in the "jars" folder, and I have used same sql instruction in apache spark non docker version and it works.
Mysql db server is also reachable from the same server I'm running the Docker.
Do I need to enable something to reach external connections? Any idea?
Reference: https://hub.docker.com/r/jupyter/all-spark-notebook
The docker-compose.yml and Dockerfile-jupyter-jars files were correct, since I was using mysql-connector-java-8.0.28.jar it requires a SSL or to disable explicitly.
jdbc:mysql://user:password#xx.xx.xx.xx:3306/inventory?useSSL=FALSE&nullCatalogMeansCurrent=true
I'm going to left this example for: Docker - all-spark-notebook with MySQL dataset

Docker file File shares on Ubuntu host

Good morning,
I am currently try to figure out how I create File shares on Ubuntu as the host OS for docker. On Windows and OSX you can set up Filesharing as below:
I require access to the File share in my docker-compose as an example see below:
version: '3.9'
services:
node_gauc:
image: node-g:v1
ports:
- "444:444" # https test port
volumes:
- ./NodeServer/cert/https.crt:/usr/share/node/cert/https.crt
- ./NodeServer/cert/key.pem:/usr/share/node/cert/key.pem
build:
context: .
dockerfile: ./NodeServer/dockerfile
restart: unless-stopped
container_name: node-g
If I don't have access when I build and start the container I get the following issues:
ERROR: for node-g Cannot start service node_g: error while creating mount source path '/usr/share/t/work/6b37be0079afed03/NodeServer/cert/https.crt': mkdir /usr/share/t: read-only file system
ERROR: for node_g Cannot start service node_g: error while creating mount source path '/usr/share/t/work/6b37be0079afed03/NodeServer/cert/https.crt': mkdir /usr/share/t: read-only file system
ERROR: Encountered errors while bringing up the project.
I am still unsure why its trying to create a directory but I suppose that is another matter.
Is it possible to create File share on a Ubuntu host server similar to what you can on OSX(Mac) or Windows OS?
Many thanks for your help

Docker unable to COPY with relative path in WSL2

I have a project that has a docker-compose.yml set up to get it running locally for development purposes. It runs great on Linux (natively) and macOS (using Docker Desktop). I am just finishing getting it running on Windows using WSL2 and Docker Desktop 2.3.0.3 (that has proper WSL2 support). The problem is that my Dockerfile is doing a COPY ./from /to command and Docker doesn't seem to be able to find the file. I have set up a minimal test to recreate the problem.
I have the project set up with this directory structure:
docker/
nginx/
Dockerfile
nginx.conf
docker-compose.yml
The nginx Dockerfile contains:
FROM nginx:1.17.9-alpine
# Add nginx configs
COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf
# Copy source code for things like static assets
COPY . /application
# Expose HTTP/HTTPS ports
EXPOSE 80 443
And the docker-compose.yml file contains:
version: "3.1"
services:
nginx:
build: docker/nginx
working_dir: /application
volumes:
- .:/application
ports:
- "80:80"
This is pretty basic - it's just copying the nginx.conf configuration file to /etc/nginx/nginx.conf inside the container.
When I run docker-compose up for this project, from the project root, inside WSL, I receive the following error:
Building nginx
Step 1/4 : FROM nginx:1.17.9-alpine
---> 377c0837328f
Step 2/4 : COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf
ERROR: Service 'nginx' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder502655363/docker/nginx/nginx.conf: no such file or directory
This is not what I expect (and not what happens on linux/mac systems) - but I assume it's messing up because of the relative path specified in the Dockerfile? Is this a Docker Desktop bug specifically with WSL, and does anybody know a workaround for the mean time? Thank you!
The path in the Dockerfile should be relative to the build context path. In this example just nginx.conf because the context path is docker/nginx.

Mounted directory empty with docker-compose and custom Dockerfile

I am very (read very) new to Docker so experimenting. I have created a very basic Dockerfile to pull in Laravel:
FROM composer:latest
RUN composer_version="$(composer --version)" && echo $composer_version
RUN composer global require laravel/installer
WORKDIR /var/www
RUN composer create-project --prefer-dist laravel/laravel site
My docker-compose.yml file looks like:
version: '3.7'
services:
laravel:
build:
context: .
dockerfile: laravel.dockerfile
container_name: my_laravel
network_mode: host
restart: on-failure
volumes:
- ./site:/var/www/site
When I run docker-compose up, the ./site directory is created but the contents are empty. I've put this in docker-compose as I plan on on including other things like nginx, mysql, php etc
The command:
docker run -v "/where/i/want/data/site:/var/www/site" my_laravel
Results in the same behaviour.
I know the install is successful as I modified my dockerfile with the follwing two lines appended to it:
WORKDIR /var/www/site
RUN ls -la
Which gives me the correct listing.
Clearly misunderstanding something here. Any help appreciated.
EDIT: So, I was able to get this to work... although, it slightly more difficult than just specifying a path..
You can accomplish this by specifying a volume in docker-compose.yml.. The path to the directory (on the host) is labeled as device in the compose file.. It appears that the root of the path has to be an actual volume (possibly a share would work) but the 'destination' of the path can be a directory on the specified volume..
I created a new volume called docker on my machine but I suppose you could do this with your existing disk/volume..
I am on a Mac and this docker-compose.yml file worked for me:
version: '3.7'
services:
nodemon-test:
container_name: my-nodemon-test
image: oze4/nodemon-docker-test
ports:
- "1337:1337"
volumes:
- docker_test_app:/app # see comment below on which name to use here
volumes:
docker_test_app: # use this name under `volumes:` for the service
name: docker_test_app
driver: local
driver_opts:
o: bind
type: none
device: /Volumes/docker/docker_test_app
The container specified exists in my DockerHub.. this is the source code for it, just in case you are worried about anything malicious. I created it like two weeks ago to help someone else on StackOverflow.
Shows files from the container on my machine (the host)..
You can read more about Docker Volume configs here if you would like.
ORIGINAL ANSWER:
It looks like you are trying to share the build directory with your host machine.. After some testing, it appears Docker will overwrite the specified path on the container with the contents of the path on the host.
If you run docker logs my_laravel you should see an error about missing files at /var/www/site.. So, even though the build is successful - once Docker mounts the directory from your machine (./site) onto the container (/var/www/site) it overwrites the path within the container (/var/www/site) with the contents of the path on your host (./site) - which is empty.
To test and make sure the contents of /var/www/site are in fact being overwritten, you can run docker exec -it /bin/bash (you may need to replace /bin/bash with /bash).. This will give you command line access inside of the container. From there you can do ls -a /var/www/site..
Furthermore, you can also pre-stage ./site to have a random test file in it (test.txt or whatever), then docker-compose up -d, then run the same commands from the step above docker exec -it ... and see if the staged test.txt file is now inside the container - this gives you definitive evidence that when you run volumes, the data on your host overwrites data in the container.
With that being said, doing something like this and sharing a log directory will work... the volume path specified on the container is still overwritten, the difference is the container is writing to that path.. it doesn't rely on it for config files/app files.
Hope this helps.

Resources