Setting up graph-tool on Docker Toolbox for WIndows - python

I followed the graph-tool docker installation instructions here. I've set up Docker Toolbox (can't use Docker for Windows, not on Pro), and I've gotten jupyter running with the Docker image.
However, I need to access a notebook in my C: drive. For the sake of this post let's say the notebook is in C:\Users\Gab\Desktop. I've successfully moved into that location, but when I run the command docker run -p 8888:8888 -p 6006:6006 -it -u user -w /home/user tiagopeixoto/graph-tool bash, it opens a bash in /home/user, not in the directory I cd'd into previously.
From what I understand, the -w /home/user is what tells it where to open, but I'm not sure how to tell it to open in the Desktop folder.
How can I set things up properly so that I can run the command jupyter notebook --ip 0.0.0.0, and still be able to access the notebook I need?
Thanks!

Here's the deal with Docker. When you execute the docker run command, what happens is that an entirely new subsystem is created which is separate from your host Operating System ( this is known as a Docker container ). This subsystem runs the tiagopeixoto/graph-tool image in it so hence the graph-tool ( and hence jupyter-notebook ) and the entrypoint /home/user is present inside this system instead of the host OS you use to run the Docker container ( in your case its Windows ). Unfortunately for you the notebook that you wish to view using jupyter-notebook isn't present inside the container and is located elsewhere ( Windows to be exact ).
What you can do in this case is mount a folder of the host Operating System to the container such that this folder contains the notebook you wish to view :-
Open a new command prompt, and type in this command as follows :- docker run -p 8888:8888 -p 6006:6006 -v /c/Users/Gab/Desktop:/mnt/temp/ -it -u user -w /home/user tiagopeixoto/graph-tool bash
The main difference to note here is the -v switch which mounts the C:\Users\Gab\Desktop volume from the host system to the Docker container in /mnt/temp/. Once that is done try viewing the notebook present in /mnt/temp in jupyter-notebook.
According to this post there exists an issue related to mounting a volume in Windows, so please check this out as well :- docker toolbox mount file on windows

Related

How to enable autocomplete when connect to docker container through CLI?

I created a docker image for my FastAPI application then I created a container from that image. Now When I connect to that container using docker exec -it <container-id> through my terminal, I am able to access it but the problem is that autocomplete doesn't work when I press TAB.
What I have understood from your question is when you enter into the docker environment, you are unable to autocomplete filenames and folders.
Usually when you enter into the container via shell, the autocomplete not works properly. Tried to enter into the container using bash environment i.e., docker exec -it <container-id> bash. Now you can use TAB to autocomplete files and folders.

how to mount a local volume for my docker?

i am newbie to the Linux and docker. I am using the below command to run the docker:
sudo nvidia-docker run --gpus all -p 8888:8888 -it -v /home/pyman/PEYMAN:??????? 21bbc6c8f7ed
where; /home/pyman/PEYMAN is my local directory
and 21bbc6c8f7ed is the image ID.
after running this command, the workspace root changes to root#0ce2ee24bac0:/workspace#
then I type jupyter notebook and run it, and it provides two links which only the second link opens the jupyter notebook in the browser.
http://hostname:8888/?token=xxxxxxxxxxx
http://127.0.0.1:8888/?token=xxxxxxxxxxx
but I dont know what is my container_dir in the first command to put in ?????, and how to get the directory. is the container_dir the same directory that jupyter is?
The container_dir is the path inside the container, where you'd like to see your mounted files. The directory inside container does not even have to exist, yon can pick almost any place to mount your files. If you work with jupyter, it makes sense to add your files to the working directory:
docker run -v /home/pyman/PEYMAN:/workspace/myfiles
Once inside the container you will find /home/pyman/PEYMAN in /workspace/myfiles.

Is there a way to modify files inside docker via PyCharm?

I want to modify files inside docker container with PyCharm. Is there possibility of doing such thing?
What you want to obtain is called Bind Mounting and it can be obtained adding -v parameter to your run command, here's an example with an nginx image:
docker run --name=nginx -d -v ~/nginxlogs:/var/log/nginx -p 5000:80 nginx
The specific parameter obtaining this result is -v.
-v ~/nginxlogs:/var/log/nginx sets up a bindmount volume that links the /var/log/nginx directory from inside the Nginx container to the ~/nginxlogs directory on the host machine.
Docker uses a : to split the host’s path from the container path, and the host path always comes first.
In other words the files that you edit on your local filesystem will be synced to the Docker folder immediately.
Source
Yes. There are multiple ways to do this, and you will need to have PyCharm installed inside the container.
Following set of instructions should work -
docker ps - This will show you details of running containers
docker exec -it *<name of container>* /bin/bash
At this point you will oh shell inside the container. If PyCharm is not installed, you will need to install. Following should work -
sudo apt-get install pycharm-community
Good to go!
Note: The installation is not persistence across Docker image builds. You should add the installation step of PyCharm on DockerFile if you need to access it regularly.

Permission Denied when using mkdir() in Docker Terminal

I am trying use Google Earth Engine's Python API on my 'Windows 10 Home' computer, for which Google recommend I set up a docker container (https://developers.google.com/earth-engine/python_install).
Following the instructions here (https://developers.google.com/earth-engine/python_install-datalab-local), I have downloaded Docker Toolbox and successfully run the docker run hello-world command.
However, when I try to run the following code:
set "GCP_PROJECT_ID=YOUR_PROJECT_ID"
set "CONTAINER_IMAGE_NAME=gcr.io/earthengine-project/datalab-ee:latest"
set "HOME=%HOMEDRIVE%%HOMEPATH%"
set "WORKSPACE=%HOME%\workspace\datalab-ee"
mkdir "%WORKSPACE%"
cd %WORKSPACE%
I get the following error on the 5th line: mkdir: cannot create directory '%WORKSPACE': Permission denied.
Does anyone know what's causing this? I have only ever use Anaconda Prompt and am not used to the syntax of this terminal.
Also, just to clarify, I entered the correct project ID into the terminal for line 1, but have not shared it here.
Problem solved. I was using the Docker Quickstart Terminal. Switched to Windows Command Prompt and everything running fine.
You may need to add yourself to the docker user group.
Run the following command in your shell or terminal window:
sudo usermod -a -G docker ${USER}
where user is the google user with which I log in to the console, after executing the command it is necessary to restart the terminal.

Is there a way to stop a command in a docker container

I have a docker container that is running a command. In the Dockerfile the last line is CMD ["python", "myprogram.py"] . This runs a flask server.
There are scenarios when I update myprogram.py and need to kill the command, transfer the updated myprogram.py file to the container, and execute python myprogram.py again. I imagine this to be a common scenario.
However, I haven't found a way to do this. Since this is the only command in the Dockerfile...I can't seem to kill it. from the containers terminal when I run ps -aux I can see that python myprogram.py is assigned a PID of 1. But when I try to kill it with kill -9 1 it doesn't seem to work.
Is there a workaround to accomplish this? My goal is to be able to change myprogram.py on my host machine, transfer the updated myprogram.py into the container, and execute python myprogram.py again.
You could use VOLUMES to mount your myprogram.py source code on your container, and just docker stop and docker restart the container.
To make a VOLUME :
add a VOLUME directive in your Dockerfile and rebuild your image :
VOLUME /path/to/mountpoint
and use the -v option when running your image.
docker run -d -v /path/to/dir/to/mount:/path/to/mountpoint myimage
/!\ These steps above are enough only for a Linux environment. /!\
To use it with something else (like Docker-machine on OSX), you must also make a mount point in the VM running Docker (probably virtualbox).
You'll have the following scheme :
<Dir to share from your host (OSX)> <= (1) mounted on => <Mountpoint on VM> <= (2) mounted on => <Container mountpoint>
The (2) is exactly like a Linux case (in fact, it IS a linux case).
The only step added is mounting the directory you want to share from your host on your VM.
Here are the steps to mount the directory you want to share on the mountpoint in your VM, and then using it with your container :
1- First stop the docker machine.
docker-machine stop <machine_name>
2- Add a sharedfolder to the VM.
VBoxManage sharedfolder add <machine_name> --name <mountpoint_name> --hostpath <dir_to_share>
3- Restart the docker machine :
docker-machine start <machine_name>
4- Creating the mountpoint with ssh and mounting the sharedfolder on it :
docker-machine ssh <machine_name> "sudo mkdir <mountpoint_in_vm>; sudo mount -t vboxsf <mountpoint_name> <mountpoint_in_vm>"
5- And then to mount the directory on your container, run :
docker run -d -v <mountpoint_in_vm>:</path/to/mountpoint (in the container)> myimage
And to clean all this when you don't need it anymore :
6- Unmount in VM :
docker-machine ssh <machine_name> "sudo umount <mountpoint_in_vm>; sudo rmdir <mountpoint_in_vm>"
7- Stop VM :
docker-machine stop <machine_name>
8- Remove shared folder :
VBoxManage sharedfolder remove <machine_name> --name <mountpoint_name>
Here is a script I made for studies purpose, feel free to use it if it can help you.
There are scenarios when I update myprogram.py and need to kill the
command, transfer the updated myprogram.py file to the container, and
execute python myprogram.py again. I imagine this to be a common
scenario.
Not really. The common scenario is either:
Kill existing container
Build new image via your Dockerfile
Boot container from new image
Or:
Start container with a volume mount pointing at your source
Restart the container when you update your code
Either one works. The second is useful for development, since it has a slightly quicker turnaround.

Categories

Resources