Skip to content

Latest commit

 

History

History
110 lines (86 loc) · 3.1 KB

docker-build.md

File metadata and controls

110 lines (86 loc) · 3.1 KB

Build and publish docker image

Build and push image

A. [RECOMMENDED] Run build.sh script to build images:

# Run build script:
./scripts/build.sh

# -p=PLATFORM, --platform=PLATFORM          Build image type [amd64 | arm64]. Default is current platform.
# -u, --push-images                         Enable pushing built images to Docker Registry.
# -c, --clean-images                        Enable clearning leftover images.
# -x, --cross-compile                       Enable cross compiling.
# -b=BASE_IMAGE, --base-image=BASE_IMAGE    Base image name. Default is "ubuntu:22.04".
# -g=REGISTRY, --registry=REGISTRY          Docker image registry (docker registry and username). Default is "bybatkhuu".
# -r=REPO, --repo=REPO                      Docker image repository. Default is "nginx".
# -v=VERSION, --version=VERSION             Docker image version. Default read from "app/__version__.py" file.
# -s=SUBTAG, --subtag=SUBTAG                Docker image subtag. Default is "".


# For example:
./scripts/build.sh -p=arm64 -u -c

# Or:
./scripts/build.sh -x

# Or:
./scripts/build.sh -p=arm64 -b=ubuntu:22.04 -n=bybatkhuu -r=nginx -v=1.0.0 -s=-arm64 -u -c

B. Or docker build command:

# Build image:
docker build \
    [IMG_ARGS] \
    --progress plain \
    --platform [PLATFORM] \
    -t $[IMG_FULLNAME] \
    .

# For example:
docker build \
    --progress plain \
    -t bybatkhuu/nginx:latest \
    .

# Push image to Docker Registry:
docker push [IMG_FULLNAME]
# For example:
docker push bybatkhuu/nginx:latest

C. Or docker buildx command (cross-compile):

# Create new builder:
docker buildx create --driver docker-container --bootstrap --use --name new_builder

# Build images and push to Docker Registry:
docker buildx build \
    [IMG_ARGS] \
    --progress plain \
    --platform linux/amd64,linux/arm64 \
    --cache-from=type=registry,ref=[IMG_NAME]:cache-latest \
    --cache-to=type=registry,ref=[IMG_NAME]:cache-latest,mode=max \
    -t [IMG_FULLNAME] \
    --push \
    .

# For example:
docker buildx build \
    --progress plain \
    --platform linux/amd64,linux/arm64 \
    --cache-from=type=registry,ref=bybatkhuu/nginx:cache-latest \
    --cache-to=type=registry,ref=bybatkhuu/nginx:cache-latest,mode=max \
    -t bybatkhuu/nginx:latest \
    --push \
    .

# Remove builder:
docker buildx rm -f new_builder

D. Or docker-compose build command:

# Build image:
docker-compose build

# Push image to Docker Registry:
docker-compose push

👍 ✨


References