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:
- Run script with desired image tag
- It will copy required folder into current directory
- Will run
docker build ...
- will remove copied folder from the current director
- In Dockerfile just add the line that removes symlink because otherwise your folder won't be copied
- Run the script and enjoy your life :)