cannot share a folder with docker container - docker

I am running a python interactive docker container on Ubuntu 14.04 using docker 17.03.1. I want to share files between local host and docker container so that files I create in the container are visible in the local directory and vice-versa. However when I run the following command I see an empty working directory in the container with no files.
docker run -e USER=$USER -e USERID=$UID -v /home/watts/python:/home/watts/python -w=/home/watts/python -p 8888:8888 --rm -it watts/python jupyter notebook --no-browser --notebook-dir=/home/watts/python --allow-root

I just run this command:
docker run -v `pwd`/home/watts/python:/home/watts/python -it kaggle/python /bin/bash
And after that, I started creating a few files both host and container. All files are visible in both sides.
Hopefully this will help.

Related

How do I transfer a volume's data to another volume on my local host in docker?

I did
docker run -v /jenkins_home:/var/jenkins_home jenkins/jenkins:alpine
on Windows (with docker installed as a linux container).
However, after configuring jenkins on that container, I now wanted to transfer the data in that /jenkins_home volume into a C:\jenkins_home folder on my local windows host machine\another machine.
Any way I can get the data from the /jenkins_home to c:/jenkins_home?
I know I should have made it
docker run -v c:/jenkins_home:/var/jenkins_home jenkins/jenkins:alpine
at the start but mistakes were made and I was wondering how do I fix that as the above suggestion?
Tried running
docker run -it -p 8080:8080 -p 50000:50000 --volumes-from jenkins_old -v c:/jenkins_home:/var/jenkins_home --name jenkins_new jenkins/jenkins:alpine
but it doesn't transfer the data over using the new c:\jenkins_home folder
docker run -v /jenkins_home:/var/jenkins_home jenkins/jenkins:alpine
Can't get the data to transfer over from the /jenkins_home folder to c:\jenkins_home folder.
I don't know where the /jenkins_home would map to on windows, but you could try this:
docker run -it --rm -v /jenkins_home:/from -v c:\jenkins_home:/to alpine cp -r /from /to

why do i keep seeing nginx index.html on localhost when i run my docker image

I installed and run nginx on my linux machine to understand the configurations etc. After a while i decided to remove it safely by following this thread in order to use it in docker
By following this documentaion i run this command
sudo docker run --name ngix -d -p 8080:80 pillalexakis/myrestapi:01
And i saw ngix's homepage at localhost
Then i deleted all ngix images & stopped all containers and i also run this command
sudo docker system prune -a
But now restarted my service by this command
sudo docker run -p 192.168.2.9:7777:8085 phillalexakis/myfirstapi:01 and i keep seeing at localhost ngix index.html
How can i totally remove it ?
Note: I'm new with docker and i might have missed a lot of things. Let me know what extra docker commands should i run in order provide better information.
Assuming your host have been preparing as below
your files (index.html, js, etc) under folder - /myhost/nginx/html
your nginx configuration - /myhost/nginx/nginx.conf
Solution
map your files (call volume) on the fly from outside docker image via docker cli
This is the command
docker run -it --rm -d -p 8080:80 --name web \
-v /myhost/nginx/html:/usr/share/nginx/html \
-v /myhost/nginx/nginx.conf:/etc/nginx/nginx.conf \
nginx
copy your files into docker image by build your own docker image via Dockerfile
This is your Dockerfile under /myhost/nginx
FROM nginx:latest
COPY ./html/index.html /usr/share/nginx/html/index.html
This is the command to build your docker image
cd /myhost/nginx
docker build -t pillalexakis/nginx .
This is the command to run your docker image
docker run -it --rm -d -p 8080:80 --name web \
pillalexakis/nginx

How to save and edit a Jupyter notebook in a host directory using official Tensorflow docker container?

I want to use the official Tensorflow docker images to create and edit a Jupyter notebook stored on the host.
I'm a little confused with what switches I need to provide. To run a Tensorflow script on the host the docs suggest:
docker run -it --rm -v $PWD:/tmp -w /tmp tensorflow/tensorflow python ./script.py
..and to run the Jupyter service:
docker run -it -p 8888:8888 tensorflow/tensorflow:nightly-py3-jupyter
When I try merging the switches to run Jupyter + mount the host volume:
docker run -it --rm -v $PWD:/tmp -w /tmp -p 8888:8888 tensorflow/tensorflow:nightly-py3-jupyter
...its still accessing notebooks stored in the container, not the host.
Notebooks are stored inside the container /tf folder, so copying your files there will do the trick:
docker run -it --rm -v $PWD:/tf -p 8888:8888 tensorflow/tensorflow:nightly-py3-jupyter
The first command you mentioned is used to run a TensorFlow program developed on the host machine, not a notebook.

Docker volume mapping not working (Linux containers)

Docker 17.09.0-ce-win33 (13620)
Running the command:
docker run --rm -it -v ${PWD}:/api -p 6000:5000 microsoft/dotnet
I should get the content of the current folder in the linux /api folder.
For some reason the mapping folder was created, yet there is not content...
cd api
ls -a
Shows an empty list...
Switching to Windows containers and running
docker run --rm -it -v ${PWD}:c:\API -p 6000:5000 microsoft/dotnet
Also gives me an empty folder...
Ran Powershell as Administrator to no avail.. any thoughts?

Docker run syntax

Can anyone clarify the syntax in this command:
$ docker run -d -P --name web -v /src/webapp:/webapp training/webapp python app.py
I can see that:
Host directory: /src/webapp
Container: /webapp
but what is training/webapp? Is that the image? If so, why is there a /?
And is everything after that (i.e. python app.py) the command that you want to run in the container?
=====
And to clarify with this command:
$ docker run -d -P --name web -v /webapp training/webapp python app.py
How does it work if you ONLY specify -v /webapp - is that equivalent to /webapp:/webapp?
You can find the documentation for docker run here
The basic structure looks like this:
$ docker run [OPTIONS] IMAGE[:TAG|#DIGEST] [COMMAND] [ARG...]
-d let's you run your docker container in detached mode, so you won't see the console output
-P publish all exposed ports to the host interfaces
--name the name of your container
-v the volume you mount host/path:container/path, where in your case /src/webapp is on your local machine and /webapp is inside your container
training/webapp is the username and image name for the docker image. I have linked the image's location on DockerHub for you
python app.pyare the command (python) and the argument run when the container starts (app.py)
Yes, training/webapp is image name. Dockerhub accept name this way only.
training is username and webapp is image name.
if you don't use dockerhub(this is image repository from docker pull image by default) and build image locally then you can give any name.
python app.py : command that will execute when docker up
--name web : this will be name of container
-v /src/webapp:/webapp : this will create volume webapp and mount on /src/webapp
--publish-all, -P : Publish all exposed ports to random ports
For more help see docker run Documentation.

Resources