last day (1015 days later) » 

3:11 PM
hello
 
thanks for the time appreciate it
 
Sadly I deleted my VM so I cannot really try for myself
No worries
 
so basically what I am trying to do is replicate the link I have shared earlier
 
Alright
So you've built your image using the Dockerfile provided
 
3:12 PM
so the only missing step there is the command to build the image
yeah, I used docker build --tag image_name .
I used the docker file in the answer
when my ${PWD} is the same as that of my original location, the folder that has the Dockerfile and scraper.py
docker run -v ${PWD}:/data image_name does indeed give me a csv in the folder
 
So the container works as expected but the python script is still the one on your host ?
 
but running that command from any other directory just throws python3: can't open file './scraper.py': [Errno 2] No such file or directory
yeah exactly
running without the -v options seems to use the python in the docker image, docker run --rm image_name this works in any location, but I dont get the csv
am I making sense?
 
Is the csv in the same folder as the Dockerfile and scraper.py ?
 
yeah
when it does work it is in the same folder
by work I mean it uses the local script
 
Can you try to run it again but set another directory for the -v option ?
 
3:20 PM
if I use a different directory I get the error I have mentioned earlier
I suck so bad at docker laurel
 
Oops, yeah just get the Dockerfile out of the way
 
wdym?
 
Try to have your Python script in another directory from the Dockerfile
How urgent is it? Do I have time to set up a VM so I can try to figure it out?
By set up I mean install docker
 
it is something I am trying out
so there is not really a deadline
 
Alright I'll install docker and try to reproduce it
 
3:27 PM
I dont want you to go above and beyond, I mean, you have your own to do
but yeah I do appreciate it
 
Don't worry about that, I love problem solving
And tbh it'll mke me go back into Docker
 
I have only been using it for like a week
many jobs ask for that, only knowing python (and not too much) has its downside in the interview time laurel
 
It's really nice
I'm not going to lie it can get tricky but overall it's fun
 
mind asking what you do? I mean, do you work?
 
I got off not long ago
 
3:31 PM
a dev?
 
Well that's complicated, I'm technically a devops
 
well, in any case I really dont want to bother you any longer
I am just going to set up a cron job and call it a day
I would rather write a 50 line shell script that will setup the environment at this stage
again, appreciate the time and effort, at least now I believe I am not making some lame mistake, you would have otherwise pointed it out
 
I'll come back to you when I'm done
Oh no I'm no expert
 
I just tried docker because it is literally everywhere I see
so anyone who has used it more than 1 week is an expert to me
 
Do what you have to do and when I find the answer I'll try to come up with a clear explanation of what happened
 
3:36 PM
sure, but again, you dont have to go out of your way
I would ask a question at main, but people most likely downvote me
you have 3k and you dont know how to write a MCVE for docker
I gtg, it is already night for me, but you can @ me over here, and have a nice day / eve
 
Alright, good night
 
 
1 hour later…
4:43 PM
@python_user Got it, I'll try to be clear
So basically WORDKIR is the equivalent of cd, so by using WORKDIR /mydata your container will be running under /mydata
Then you use ADD scraper.py ./, so inside your container you'll have /mydata/scraper.py
Finally with CMD you tell your container to execute python3 ./scraper.py, or python3 /mydata/scraper.py (because of WORDKIR)
When using the -v option, you link a folder from your container to your host. This can be useful when you need to exchange files between the two.
Using -v ${PWD}:/mydata you link your host PWD to the folder /mydata inside your container
So since the CMD python3 ./scraper.py is CMD python3 /mydata/scraper.py, it now (-v) the same as CMD python3 ${PWD}/scraper.py
That is why you are running your local script, because the two are the same file
What we want here is to only bind the data (output.csv)
There are pultiple ways of fixing this
First, we can swap COPY and WORKDIR so that you copy the script at the root of the container and then you cd into /mydata
Then you modify CMD to execute /scraper.py instead of ./scraper.py
Now you can rebuild your image, same as before
Finally, create a folder on your host ${PWD}/data
Then run docker run -v ${PWD}/data:/mydata image_name
See now we linked files only containing data so no chance of mixing scripts here
I hope that was clear enough, if not don't hesitate
 

  last day (1015 days later) »