how to save file from docker container to local downloads folder - r

I am running a R and python script in a docker container. both scripts save the file to the working folder, but when running a container, there is no local folder.
what changes do I need to ensure that the file goes to the downoads folder of the person running the container?
do I need to update my R and python scrips such that the files are saved to the local host download? If so, what would that look like, as there is not a localhost.
In R, I updated my saving file location to :
write.csv(data,
paste0('C:/Users/',Sys.getenv("USERNAME"),'/Downloads/file_made_by_r_script.csv'))
but while running the container, the resulting file is not found in my downloads folder.
I tried mounting a volume as per Write files outside of a docker container via python, but cannot do that while the container is hosted in azure

Related

Heroku dyno automatically deleting files and folders which is created using terminal

I am creating logs file on heroku using "winston" module. It creates a log files on local system an writing a logs in file, but when I deployed it on heroku server then log file is not generated, If I create log file manually on heroku using heroku terminal or bash, then file and folder automatically get deleted.
I tried to push log folder and files using git but server log is not writing in log file on server and same code is working on local.

How do I copy the files from one directory to another using a dockerfile?

I am using an ec2 instance with docker. I am creating a docker file that uses a Nginx image. I have two directories on my ec2 one is called Docker (this is where the Dockerfile is located) and the other main, I want to copy the contents of main into the directory /usr/share/nginx/html using the docker file. I have tried it like this but keep on getting an error of the file/directory not existing.
ADD /home/ec2-user/main/ /usr/share/nginx/html
in the main directory, I just have one file called one.html

How to Copy a Local Directory to an Apache Server

I have a directory on my desktop and need to copy it to my server. I've looked up a command to do this being
scp -r /path/to/local/storage user#remote.host:/path/to/copy
but when I run it, it just tells me "No suck file or directory".
First of all is this the correct way to do this or is there an easier way to take a directory from local storage and put it onto an apache server? Once I get it on the server I can move it around just fine there. I just need to get it on there!
the path I'm using right now for local is
/Users/byw5k_000/Desktop/myWebsite
with myWebsite being the directory I want to copy onto my server.
I'm curious if I'm getting the path incorrect. What is the correct path to the desktop on a windows 10 computer and will this work for me to copy an entire directory onto an apache server?
You could try changing to your Desktop directory like this:
cd C:\Users\(username)\Desktop
and then running:
scp -r myWebsite user#remote.host:/path/to/copy
Should work as ling as you can change to your Desktop directory

Passing environment variables through jar file which app uses

I am currently trying out on the docker link between my app and db containers. I've checked on my app container and environment variables are automatically set when I link the containers together.
What I want to do is for my config file, which is packaged into a jar file, to receive the environment variables and set the required values to it. Any advice or help?
And this is how I create a config file in my jar file to connect to MySQL
database { url="jdbc:mysql://${MYSQL_PORT_3306_TCP_ADDR}:${MYSQL_PORT_3306_TCP_PORT}/mydb" driver="com.mysql.jdbc.Driver"}
Updating the config file inside the jar could be quite overkill.
It think you have several choices
read the config environment variable directly in you program
use variable either directly or generate the config file there
create launch script (details of this depends of you guest os in docker how to do it; sh/bash for linux etc..)
that script can generate new config file from environment and put it on classpath before jar so you program sees it.
EDIT: added example
You can save this kind of launcher script on docker image which dynamically creates configuration before launching actual program.
#!/bin/bash
# some default values for testing even without links to other container
MYSQL_PORT_3306_TCP_ADDR=${MYSQL_PORT_3306_TCP_ADDR:-127.0.0.1}
MYSQL_PORT_3306_TCP_PORT=${MYSQL_PORT_3306_TCP_PORT:-3306}
cat << EOF > /opt/yourprogram/dbconfig.conf
database { url="jdbc:mysql://${MYSQL_PORT_3306_TCP_ADDR}:${MYSQL_PORT_3306_TCP_PORT}/mydb" driver="com.mysql.jdbc.Driver"
}
EOF
scala -classpath /opt/yourprogram YourProgram
What I did is that I wrote the sh file in my directory /tmp/restcore-1.0-SNAPSHOT/bin like this:
#!/bin/bash echo "database{url="jdbc:mysql://"${MYSQL_PORT_3306_TCP_ADDR}":"${MYSQL_PORT_3306_TCP_PORT}"/mydb" driver="com.mysql.jdbc.Driver" }" > myconf.conf
jar uf /tmp/restcore-SNAPSHOT/lib/com.organization.restcore-1.0-SNAPSHOT.jar /tmp/restcore-1.0-SNAPSHOT/bin/myconf.conf
After building the Dockerfile and running the sh file in CMD, I use cat myconf.conf to check the config file and I'll be able to see the environment set.

Setting IPython Notebook save directory when using through django_extensions

I am using IPython Notebook through django_extensions:
python manage.py shell_plus --notebook
This saves the Notebook files to the current folder (Django project folder). How can I change the save location for .ipynb files?
You can change the directories where files are stored and read from using these parameters in ~/.ipython/profile_projectname/ipython_notebook_config.py, where projectname is your Django project.
c.NotebookManager.notebook_dir = u'/path/to/files'
c.FileNotebookManager.notebook_dir = u'/path/to/files'
This seems to ruin the import path to django however. I've been trying to play around with syspath to get this right via adding startup scripts in the startup directory, but have not found a solution that works yet. If you find a solution, let me know, because I'd like to have my notebook files outside of my project root directory as well.
A little late to the game, but I managed to save the notebooks in a different location + auto importing Django settings.
I start my notebooks with:
PYTHONPATH=/path/to/project/root DJANGO_SETTINGS_MODULE=settings python manage.py --notebook --no-browser
The PYTHONPATH enables finding the correct modules of my project and all shell_plus imports work automatically like a charm.
P.S.
As I am running this command executed from my host in my vagrant box --no-browser prevents opening w3m ^^

Resources