Quantcast
Channel: How to include files outside of Docker's build context? - Stack Overflow
Viewing all articles
Browse latest Browse all 23

Answer by Anatoly for How to include files outside of Docker's build context?

$
0
0

My workaround for the issue. Looked for elegant solution that I won't need to reinvent every time when I build image, and decided to create the following build-docker.sh bash script:

#!/bin/bash# Check if a tag argument is providedif [ "$#" -ne 1 ]; then    echo "Usage: $0 <tag>"    exit 1fi# Assign the tag argument to a variableTAG=$1# Copy the source-code directorycp -R ../source-code ./temp-source-code# Run the Docker build command with the specified tagdocker build -t "$TAG" .# Check if Docker build was successfulif [ $? -eq 0 ]; then    echo "Docker build successful, removing temp-source-code directory..."    rm -rf ./temp-source-codeelse    echo "Docker build failed, temp-source-code directory not removed."fi

In Dockerfile:

# Copy the rest of your application's source codeCOPY . .# Remove the existing symlinkRUN rm -f ./src/source-code# Copy lambda parserCOPY ./temp-source-code ./src/source-code

In summary:

  1. Run script with desired image tag
  2. It will copy required folder into current directory
  3. Will run docker build ...
  4. will remove copied folder from the current director
  5. In Dockerfile just add the line that removes symlink because otherwise your folder won't be copied
  6. Run the script and enjoy your life :)

Viewing all articles
Browse latest Browse all 23

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>