Search code examples
bashdockerdockerfile

Dockerfile COPY ".env" directory


How can I use COPY in Dockerfile to copy folder of which name starts with a dot?

FROM confluentinc/cp-kafka-connect:6.0.0

# does not work
COPY ./aws/ /home/appuser/.aws

EXPOSE 8083

Directory structure:

/MyFolder
├── .aws
│   └── credentials
└── Dockerfile

Solution

  • COPY ./aws [DESTINATION] is "COPY, from the current directory './', the directory named 'aws' to the [DESTINATION]".

    COPY ./.aws [DESTINATION] will COPY the hidden directory '.aws' from the current directory './' to [DESTINATION].

    COPY ./.aws/ /home/appuser/.aws will result in /home/appuser/.aws/credentials existing in the built image.


    Tip: [DESTINATION] is created by COPY if it doesn't already exist.

    Note: if the directory is ignored in a .dockerignore then the COPY will not work.

    Note: should never COPY credentials in an image if you intend on sharing the image rather bind-mount the credentials during the containers runtime i.e. docker run --rm -it -v ./.aws/credentials:/home/appuser/.aws/credentials:ro myimage