Jump to content
  • 0

WORKDIR in dockerfile


Question

I'm yoused to using cd when shifting level; but in docker you only have to use WORKDIR every time you make a change of level(as many as you like). PROBLEM: I can see that ./ is the toplevel and I have seen examples like WORKDIR /A/B/C (I believe it must be to go to level 3 C). I have tried (almost every possibility); but are still not near!

I have a repository in github https://github.com/JupyterPS/Slimline where I want to move item requirements.txt into folder CONFIG, that means shifting one level down.

What  would that look like in my dockerfile apart from ./?

Looking forward to see a good solution, thank you

 

Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0
14 minutes ago, henning reckey said:

I'm yoused to using cd when shifting level; but in docker you only have to use WORKDIR every time you make a change of level(as many as you like). PROBLEM: I can see that ./ is the toplevel and I have seen examples like WORKDIR /A/B/C (I believe it must be to go to level 3 C). I have tried (almost every possibility); but are still not near!

I have a repository in github https://github.com/JupyterPS/Slimline where I want to move item requirements.txt into folder CONFIG, that means shifting one level down.

What  would that look like in my dockerfile apart from ./?

Looking forward to see a good solution, thank you

 

Hi henning,

You don't have to use relative paths in WORKDIR. You can use absolute paths as WORKDIR if you want.

 

WORKDIR /path/to/CONFIG/folder

That's all you need to navigate to the CONFIG directory.

 

If you just want to copy the item requirements.txt to the CONFIG directory of your Docker container, you can use the COPY command like this:

COPY requirements.txt /path/to/CONFIG/folder

 

I hope this helps.

Shovon

Link to post
Share on other sites
  • 0

 Hi again .......Tried this, but

COPY requirements.txt  /config/requirements.txt                                                                                                             stmt in dockerfile

COPY failed: stat /var/lib/docker/temp/docker-builder240834602/requirements.txt: no such file or directory          when building 
 

Docker.txt Docker.rtf Docker.rtf

Link to post
Share on other sites
  • 0
3 hours ago, henning reckey said:

 Hi again .......Tried this, but

COPY requirements.txt  /config/requirements.txt                                                                                                             stmt in dockerfile

COPY failed: stat /var/lib/docker/temp/docker-builder240834602/requirements.txt: no such file or directory          when building 
 

Docker.txt 3 B · 3 downloads Docker.rtf 1.36 MB · 0 downloads Docker.rtf 1.36 MB · 0 downloads

Do you have the requirements.txt file in the current working directory of the Docker host? 

Link to post
Share on other sites
  • 0
46 minutes ago, henning reckey said:

Hi

You see that's my problem, I don't know much of what's going on, on the host (that's why I'm curious). Do you have a chance to look into my repository so you can see what I'm trying to do? https://github.com/JupyterPS/Slimline

Thanks for your time

I think, you want to copy the project to the Docker container's HOME directory. The project is in the config/ directory.

image.thumb.png.5846e8a8474ffa3e5e03d25e04fb868d.png

 

To copy the whole project into your Docker container, do the following steps:

1) Run  cd $HOME  in your Docker host. This will take you to your HOME directory.

2) Clone the git project in the HOME directory. Let's say, the project is in the myproject directory in your Docker host. 

3) Navigate to myproject/ directory with cd myproject

4) In your  Dockerfile , add the following line to copy the config/ directory to the HOME directory of your Docker container.

ADD config ~

5) Now you should have a config/ directory in the HOME directory of your Docker container. You should be able to access the requirements.txt file using the path ~/config/requirements.txt in your Docker container.

6) RUN python -m pip  install -r requirements.txt -> can now be -> RUN python -m pip  install -r ~/config/requirements.txt

7) You can use absolute path from this point. You can reference any file using the absolute path ~/config/<filename> in your Docker container.

 

I hope this helps.

Shovon

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...