0

I have a source code and I want to add it into docker image using Dockerfile. I use COPY command, but I don't know what I should put in destination place. Can you tell me if destination is a specific directory or it is optional?

taraf
  • 777
  • 2
  • 10
  • 28

3 Answers3

5

The destination directory can be a directory of your choice.

    ...

    RUN mkdir -p /usr/src/app
    COPY ./src /usr/src/app

    ...

The above commands in a Dockerfile would create /usr/src/app in the containers filesystem and the COPY would copy the contents of the src directory on the host to /usr/src/app in the containers filesystem.

Faz
  • 360
  • 3
  • 11
3

You can use any destination path , but make sure that path exist for example

COPY source_code / opt/folder_name

Then optionally you can make this in docker as working directory

WORKDIR /opt/folder_name

sanath meti
  • 5,179
  • 1
  • 21
  • 30
1

in Dockerfile:

COPY ./src /dst

Where src is a folder in the same path of Dockerfile on the host (the computer on which Docker is directly running). dst is a folder on the container itself.

Here is an example:

Create a Dockerfile for an ASP.NET Core application

# Copy everything

COPY . /FolderInTheContainer/

this will copy everything in the same path of Dockerfile, to a destination folder in the container.


Here is dockerfile copy documentation:

https://docs.docker.com/engine/reference/builder/#copy

Community
  • 1
  • 1
Mohammed Noureldin
  • 14,913
  • 17
  • 70
  • 99