Mount a local data directory into jupyterhub - docker

I build and run jupyterhub a docker image. https://hub.docker.com/r/joergklein/jupyterhub
Is it a good idea to mount in the Dockerfile
# Create a mountpoint
VOLUME /data
or is it better to mount to
# Create a mountpoint
VOLUME /home/data
I have a local data dir on my computer. I will mount the data dir into the container /data or /home/data.
At first I download and install the image
docker run -p 8000:8000 -d --name jupyterhub joergklein/jupyterhub jupyterhub
Second I will mount the datasets dir. into the /data in the container. In the dataset dir are a lot of csv files.
docker run -v /home/user/datasets:/data -t jupyterhub /bin/bash
I want run the JupyterHub in a sub domain in a team.
We want share the data. How can all team member work in this directory?
How we can add new data in this directory?
Which is the right docker run commnd?

That works fine for me.
docker run -p 8000:8000 -d --name jupyterhub --volume $(pwd)/datasets:/data joergklein/jupyterhub jupyterhub

Related

Docker Apache Mounts and Permissions

I've just started dabbling with Docker. I notice that when directly pulling the PHP-Apache image and mounting a volume, this works fine:
docker run -d -p 80:80 --name php-try -v C:\Users\me\Desktop\php-try:/var/www/html php:7.2-apache
But when I build an image with a Dockerfile, copying the contents of the working directory to the usual /var/www/html folder, and then try to run a container with a volume or bind mount docker run -d -p 80:80 php-try -v C:\Users\me\Desktop\php-try:/var/www/html the container simply exits/doesn't run. Without the attempt to mount a volume, it runs fine.
The Dockerfile is simply:
FROM php:7.2-apache
COPY . /var/www/html/
Grateful for any help with this.

Docker file in host machine not available in container using bind volume

I am facing an issue where after runnig the container and using bind mount to mount the directory on host to container I am not able to see new files created in host machine inside container.Below is my project structure.
The python code creates a file inside the container which should be available inside the host machine too however this does happen when I start the container with below command. However updates to python code and html is available inside the container.
sudo docker container run -p 5000:5000 --name flaskapp --volume feedback1:/app/feedback/ --volume /home/deepak/PycharmProjects/NewDockerProject/sampleapp:/app flask_image
However after starting the container using below command, everything seems to work fine. I can see all the files from container to host and vice versa(new created , edited).I git this command from docker in the month of lunches book.
sudo docker container run --mount type=bind,source=/home/deepak/PycharmProjects/NewDockerProject/sampleapp,target=/app -p 5000:5000 --name flaskapp
Below is the content of my dockerfile
FROM python:3.8-alpine
WORKDIR /app
COPY ./requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python","main.py"]
Could someone please help me in figuring out the difference between the two commands ? I am using ubuntu. Thank you
In my case i got working volumes using following docker run args (but i am running without --mount type=bind):
docker run -it ... -v mysql_data:/var/lib/mysql -v storage:/usr/shared/app_storage
where:
mysql_data is a volume name
/var/lib/mysql path inside container machine
you could list volumes as:
docker volume ls
and inspect them to see where it points on your system (usually /var/lib/docker/volumes/{volume_nanme}/_data):
docker volume inspect mysql_data
to create volume use following command:
docker volume create {volume_name}

Dockerfile : How to mount host directory in container path?

If i have inside my localhost a log folder at:
/var
/logs
apache.logs
elasticsearch.logs
etc...
And i want to mount /var/logs directory of my host, into a path inside a Docker container, like /usr/var/logs/ , how do i do that within a dockerfile ? So each time a log file is updated, it would be accessible within the container too.
Thank you
You can not mount a volumn in Dockerfile
Because:
Dockerfile will build an image, image is independent on each machine host.
Image should be run everywhere on the same platform for example on linux platform it can be running on fedora, centos, ubuntu, redhat...etc
So you just mount volumn in to the container only. because container will be run on specify machine host.
Hope you understand it. Sorry for my bad English.
You can achieve it in two ways - https://docs.docker.com/storage/bind-mounts/
--mount
$ docker run -d -it --name devtest --mount type=bind,source=/var/logs,target=/usr/var/logs image:tag
-v
$ docker run -d -it --name devtest -v /var/logs:/usr/var/logs image:tag
Try -v option of docker run command.
docker run -itd -v /var/logs:/usr/var/logs image-name
This will mount /var/logs directory of host on to /usr/var/logs directory of container.
Hope this helps.
Update:
To mount directory with source and dest in dockerfile make use of this hack (Not 100% sure though).
RUN --mount=target=/usr/var/logs,type=bind,source=/var/logs

How to copy files from Docker container to bind mount directory on docker run?

In my Dockerfile, I copy a config file over like so:
VOLUME ["/root/.litecoin"]
WORKDIR $HOME/.litecoin
COPY litecoin.conf .
I'm able to start the docker container with the config file if I use a named or unanamed volume:
docker run -d --name litecoind -v litecoin-blockchain:/root/.litecoin -t test
or
docker run -d --name litecoind -v /root/.litecoin -t test
However, if I try with a bind mount (empty directory), it overwrites the contents of /root/.litecoin and I lose my config. E.g:
docker run --name litecoind -v /mnt/LV_LTC:/root/.litecoin -t test
What is the best non-hacky way to get config files copied from the host to the container using bind mounts? It's annoying that my self-contained Docker app is breaking because I need to use bind mounts (block storage).

Mount a Host Directory as a Data Volume in docker?

when i try to mount a host directory as data volume in docker its not mount any directory to docker container(image).
When i run
sudo docker run -t -i --name web -v /home/rponna/src/webapp:/opt/webapp ramnathreddy
it returns container id
7dcc03c397d56514015220a073c9e951478bf84aceb90b880bb93a5716079212
But when i run that container it will not show any files in opt/webapp (its empty).

Resources