Dockerfile ADD . is adding wrong directory












0















.
|-- business_logic
| ....
|
|-- docker-compose.yml
|-- src
| `-- backend
| |-- Dockerfile
| |-- manage.py
| |-- requirements.txt
| `-- webapp
| |-- __init__.py
| |-- settings.py
| |-- urls.py
| `-- wsgi.py
`-- utils.py


I want Docker to copy ./src/backend/ to /code/ on the container and when I'm running this compose file:



version: '3'

services:
db:
image: postgres
web:
build:
context: ./src/backend/
command: ls -l .
volumes:
- .:/code/
ports:
- "8000:8000"
depends_on:
- db


With the Dockerfile under backend:



FROM python:3
ENV PYTHONUNBUFFERED 1

RUN mkdir /code
WORKDIR /code

ADD requirements.txt /code/
RUN pip install -r requirements.txt

ADD . /code/


I would expect that the Dockerfile-position in the file tree or the context would be the relative path "." in the Dockerfile, but it seems as if "." points to the directory where docker-compose.yml lies. Because the output is following:



web_1  | drwxr-xr-x 14 root root 448 Jan  2 01:51 business_logic
web_1 | -rw-r--r-- 1 root root 207 Jan 2 03:10 docker-compose.yml
web_1 | drwxr-xr-x 3 root root 96 Jan 2 02:34 src
web_1 | -rw-r--r-- 1 root root 657 Jan 2 01:51 utils.py


How to copy only everything below the backend-folder into code?










share|improve this question



























    0















    .
    |-- business_logic
    | ....
    |
    |-- docker-compose.yml
    |-- src
    | `-- backend
    | |-- Dockerfile
    | |-- manage.py
    | |-- requirements.txt
    | `-- webapp
    | |-- __init__.py
    | |-- settings.py
    | |-- urls.py
    | `-- wsgi.py
    `-- utils.py


    I want Docker to copy ./src/backend/ to /code/ on the container and when I'm running this compose file:



    version: '3'

    services:
    db:
    image: postgres
    web:
    build:
    context: ./src/backend/
    command: ls -l .
    volumes:
    - .:/code/
    ports:
    - "8000:8000"
    depends_on:
    - db


    With the Dockerfile under backend:



    FROM python:3
    ENV PYTHONUNBUFFERED 1

    RUN mkdir /code
    WORKDIR /code

    ADD requirements.txt /code/
    RUN pip install -r requirements.txt

    ADD . /code/


    I would expect that the Dockerfile-position in the file tree or the context would be the relative path "." in the Dockerfile, but it seems as if "." points to the directory where docker-compose.yml lies. Because the output is following:



    web_1  | drwxr-xr-x 14 root root 448 Jan  2 01:51 business_logic
    web_1 | -rw-r--r-- 1 root root 207 Jan 2 03:10 docker-compose.yml
    web_1 | drwxr-xr-x 3 root root 96 Jan 2 02:34 src
    web_1 | -rw-r--r-- 1 root root 657 Jan 2 01:51 utils.py


    How to copy only everything below the backend-folder into code?










    share|improve this question

























      0












      0








      0








      .
      |-- business_logic
      | ....
      |
      |-- docker-compose.yml
      |-- src
      | `-- backend
      | |-- Dockerfile
      | |-- manage.py
      | |-- requirements.txt
      | `-- webapp
      | |-- __init__.py
      | |-- settings.py
      | |-- urls.py
      | `-- wsgi.py
      `-- utils.py


      I want Docker to copy ./src/backend/ to /code/ on the container and when I'm running this compose file:



      version: '3'

      services:
      db:
      image: postgres
      web:
      build:
      context: ./src/backend/
      command: ls -l .
      volumes:
      - .:/code/
      ports:
      - "8000:8000"
      depends_on:
      - db


      With the Dockerfile under backend:



      FROM python:3
      ENV PYTHONUNBUFFERED 1

      RUN mkdir /code
      WORKDIR /code

      ADD requirements.txt /code/
      RUN pip install -r requirements.txt

      ADD . /code/


      I would expect that the Dockerfile-position in the file tree or the context would be the relative path "." in the Dockerfile, but it seems as if "." points to the directory where docker-compose.yml lies. Because the output is following:



      web_1  | drwxr-xr-x 14 root root 448 Jan  2 01:51 business_logic
      web_1 | -rw-r--r-- 1 root root 207 Jan 2 03:10 docker-compose.yml
      web_1 | drwxr-xr-x 3 root root 96 Jan 2 02:34 src
      web_1 | -rw-r--r-- 1 root root 657 Jan 2 01:51 utils.py


      How to copy only everything below the backend-folder into code?










      share|improve this question














      .
      |-- business_logic
      | ....
      |
      |-- docker-compose.yml
      |-- src
      | `-- backend
      | |-- Dockerfile
      | |-- manage.py
      | |-- requirements.txt
      | `-- webapp
      | |-- __init__.py
      | |-- settings.py
      | |-- urls.py
      | `-- wsgi.py
      `-- utils.py


      I want Docker to copy ./src/backend/ to /code/ on the container and when I'm running this compose file:



      version: '3'

      services:
      db:
      image: postgres
      web:
      build:
      context: ./src/backend/
      command: ls -l .
      volumes:
      - .:/code/
      ports:
      - "8000:8000"
      depends_on:
      - db


      With the Dockerfile under backend:



      FROM python:3
      ENV PYTHONUNBUFFERED 1

      RUN mkdir /code
      WORKDIR /code

      ADD requirements.txt /code/
      RUN pip install -r requirements.txt

      ADD . /code/


      I would expect that the Dockerfile-position in the file tree or the context would be the relative path "." in the Dockerfile, but it seems as if "." points to the directory where docker-compose.yml lies. Because the output is following:



      web_1  | drwxr-xr-x 14 root root 448 Jan  2 01:51 business_logic
      web_1 | -rw-r--r-- 1 root root 207 Jan 2 03:10 docker-compose.yml
      web_1 | drwxr-xr-x 3 root root 96 Jan 2 02:34 src
      web_1 | -rw-r--r-- 1 root root 657 Jan 2 01:51 utils.py


      How to copy only everything below the backend-folder into code?







      django docker






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 3:23









      sebseb

      3,25221728




      3,25221728
























          1 Answer
          1






          active

          oldest

          votes


















          2














          In docker-compose when you are using volume to map it is mapping your current directory (which is in parallel with docker-compose.yml) , however in case of Dockerfile "." means current directory with respect to docker-context (./src/backend/) that you set.



          Here after Docker image preparation, while creating container volume is causing override.
          hint - Use the same docker-context first and then adjust paths accordingly.



          Try following docker-compose.yml



              version: '3'

          services:
          db:
          image: postgres
          web:
          build:
          context: ./src/backend/
          command: ls -l .
          volumes:
          - ./src/backend/:/code/
          ports:
          - "8000:8000"
          depends_on:
          - db





          share|improve this answer



















          • 1





            (To answer the question implied by the title: ADD is working correctly, but your volumes: line is hiding the work the Dockerfile does.)

            – David Maze
            Jan 2 at 11:15











          • And how to remove the overwriting of the Dockerfile location? Without doing it explicitly?

            – seb
            Jan 2 at 13:42













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000876%2fdockerfile-add-is-adding-wrong-directory%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          In docker-compose when you are using volume to map it is mapping your current directory (which is in parallel with docker-compose.yml) , however in case of Dockerfile "." means current directory with respect to docker-context (./src/backend/) that you set.



          Here after Docker image preparation, while creating container volume is causing override.
          hint - Use the same docker-context first and then adjust paths accordingly.



          Try following docker-compose.yml



              version: '3'

          services:
          db:
          image: postgres
          web:
          build:
          context: ./src/backend/
          command: ls -l .
          volumes:
          - ./src/backend/:/code/
          ports:
          - "8000:8000"
          depends_on:
          - db





          share|improve this answer



















          • 1





            (To answer the question implied by the title: ADD is working correctly, but your volumes: line is hiding the work the Dockerfile does.)

            – David Maze
            Jan 2 at 11:15











          • And how to remove the overwriting of the Dockerfile location? Without doing it explicitly?

            – seb
            Jan 2 at 13:42


















          2














          In docker-compose when you are using volume to map it is mapping your current directory (which is in parallel with docker-compose.yml) , however in case of Dockerfile "." means current directory with respect to docker-context (./src/backend/) that you set.



          Here after Docker image preparation, while creating container volume is causing override.
          hint - Use the same docker-context first and then adjust paths accordingly.



          Try following docker-compose.yml



              version: '3'

          services:
          db:
          image: postgres
          web:
          build:
          context: ./src/backend/
          command: ls -l .
          volumes:
          - ./src/backend/:/code/
          ports:
          - "8000:8000"
          depends_on:
          - db





          share|improve this answer



















          • 1





            (To answer the question implied by the title: ADD is working correctly, but your volumes: line is hiding the work the Dockerfile does.)

            – David Maze
            Jan 2 at 11:15











          • And how to remove the overwriting of the Dockerfile location? Without doing it explicitly?

            – seb
            Jan 2 at 13:42
















          2












          2








          2







          In docker-compose when you are using volume to map it is mapping your current directory (which is in parallel with docker-compose.yml) , however in case of Dockerfile "." means current directory with respect to docker-context (./src/backend/) that you set.



          Here after Docker image preparation, while creating container volume is causing override.
          hint - Use the same docker-context first and then adjust paths accordingly.



          Try following docker-compose.yml



              version: '3'

          services:
          db:
          image: postgres
          web:
          build:
          context: ./src/backend/
          command: ls -l .
          volumes:
          - ./src/backend/:/code/
          ports:
          - "8000:8000"
          depends_on:
          - db





          share|improve this answer













          In docker-compose when you are using volume to map it is mapping your current directory (which is in parallel with docker-compose.yml) , however in case of Dockerfile "." means current directory with respect to docker-context (./src/backend/) that you set.



          Here after Docker image preparation, while creating container volume is causing override.
          hint - Use the same docker-context first and then adjust paths accordingly.



          Try following docker-compose.yml



              version: '3'

          services:
          db:
          image: postgres
          web:
          build:
          context: ./src/backend/
          command: ls -l .
          volumes:
          - ./src/backend/:/code/
          ports:
          - "8000:8000"
          depends_on:
          - db






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 2 at 5:01









          fly2matrixfly2matrix

          1,14958




          1,14958








          • 1





            (To answer the question implied by the title: ADD is working correctly, but your volumes: line is hiding the work the Dockerfile does.)

            – David Maze
            Jan 2 at 11:15











          • And how to remove the overwriting of the Dockerfile location? Without doing it explicitly?

            – seb
            Jan 2 at 13:42
















          • 1





            (To answer the question implied by the title: ADD is working correctly, but your volumes: line is hiding the work the Dockerfile does.)

            – David Maze
            Jan 2 at 11:15











          • And how to remove the overwriting of the Dockerfile location? Without doing it explicitly?

            – seb
            Jan 2 at 13:42










          1




          1





          (To answer the question implied by the title: ADD is working correctly, but your volumes: line is hiding the work the Dockerfile does.)

          – David Maze
          Jan 2 at 11:15





          (To answer the question implied by the title: ADD is working correctly, but your volumes: line is hiding the work the Dockerfile does.)

          – David Maze
          Jan 2 at 11:15













          And how to remove the overwriting of the Dockerfile location? Without doing it explicitly?

          – seb
          Jan 2 at 13:42







          And how to remove the overwriting of the Dockerfile location? Without doing it explicitly?

          – seb
          Jan 2 at 13:42






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000876%2fdockerfile-add-is-adding-wrong-directory%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith