1

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?

1
  • Which docker image you are using? Commented Dec 23, 2017 at 10:38

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

its not WORDIR. its WORKDIR WORKDIR /opt/folder_name
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.