Skip to content

Commit

Permalink
Fix .dockerignore handling so it works on both docker and podman
Browse files Browse the repository at this point in the history
  • Loading branch information
regularfry committed Mar 28, 2024
1 parent 29fa0cb commit 29ef7b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/developer-guides/Scripting_Docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ For cross-platform image support, the `--platform linux/amd64` flag is used to b

### Dockerignore file

If you need to exclude files from a `COPY` command, put a `.dockerignore` file next to the relevant `Dockerfile`. They do not live in the root directory.
If you need to exclude files from a `COPY` command, put a [`Dockerfile.dockerignore`](https://docs.docker.com/build/building/context/#filename-and-location) file next to the relevant `Dockerfile`. They do not live in the root directory. Any paths within `Dockerfile.dockerignore` must be relative to the repository root.

## FAQ

Expand Down
17 changes: 9 additions & 8 deletions scripts/docker/docker.lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ function docker-build() {
version-create-effective-file
_create-effective-dockerfile

# The .dockerignore file is optional
ignore=""
if [ -f "${dir}/.dockerignore" ]; then
ignore="--ignorefile ${dir}/.dockerignore"
fi

tag=$(_get-effective-tag)

docker build \
Expand All @@ -51,7 +45,6 @@ function docker-build() {
--tag "${tag}" \
--rm \
--file "${dir}/Dockerfile.effective" \
${ignore} \
.

# Tag the image with all the stated versions, see the documentation for more details
Expand Down Expand Up @@ -141,7 +134,8 @@ function docker-clean() {
done
rm -f \
.version \
Dockerfile.effective
Dockerfile.effective \
Dockerfile.effective.dockerignore
}

# Create effective version from the VERSION file.
Expand Down Expand Up @@ -234,6 +228,13 @@ function _create-effective-dockerfile() {

local dir=${dir:-$PWD}

# If it exists, we need to copy the .dockerignore file to match the prefix of the
# Dockerfile.effective file, otherwise docker won't use it.
# See https://docs.docker.com/build/building/context/#filename-and-location
# If using podman, this requires v5.0.0 or later.
if [ -f "${dir}/Dockerfile.dockerignore" ]; then
cp "${dir}/Dockerfile.dockerignore" "${dir}/Dockerfile.effective.dockerignore"
fi
cp "${dir}/Dockerfile" "${dir}/Dockerfile.effective"
_replace-image-latest-by-specific-version
_append-metadata
Expand Down

0 comments on commit 29ef7b1

Please sign in to comment.