Giter Site home page Giter Site logo

doytsujin / docker-buildx-multiarch-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from erriez/docker-buildx-multiarch-example

0.0 1.0 0.0 20 KB

Docker buildx Hello World application

License: MIT License

Shell 11.74% HCL 58.61% Dockerfile 29.65%

docker-buildx-multiarch-example's Introduction

CI License Tag

Docker buildx bake Hello World

This is an example project to build multi-architecture Docker images with buildx and test Github Actions on a local machine with Act.

Installation

# Install Docker v20+
https://docs.docker.com/engine/install/

Directory / file structure

# Configure Github Actions
.github/workflows/CI.yml

# Configure configuration script for docker buildx bake
build.hcl

# Example builds cript
build.sh

# Docker example project files
alpine-hello/Dockerfile
ubuntu-hello/Dockerfile

# Environment variables
.env
.secret

Build locally

# Build all images for all platforms
docker buildx bake -f build.hcl

# Build one image for all platforms
docker buildx bake -f build.hcl alpine-hello

# Build all images for one or more platforms
docker buildx bake -f build.hcl --set *.platform=linux/amd64,linux/arm64,linux/arm/v7

# Build all images for current platform and load into local Docker registry (--load option)
docker buildx bake -f build.hcl --load

# Build all images for all platforms and push to registry (--push option)
docker login [registry]
docker buildx bake -f build.hcl --push

Build script:

# Build all images for all platforms
./build.sh [arguments]

Run locally

Run image from registry. Output on AMD64:

docker run -it --rm erriez/alpine-hello:latest
x86_64
Hello World from Alpine container!

docker run -it --rm erriez/ubuntu-hello:latest
x86_64
Hello World from Ubuntu container!

Output on ARM64 (for example Raspberry Pi 4): aarch64.

Test Github Actions locally with Act

# Install Act locally to run Github Actions locally
curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash

# Run all jobs
act

# Run single job
act -j Build

# Run with env file and secret file
act --env-file .env --secret-file .secret

# .env file
DOCKER_ORG=<your_name>
DOCKER_PREFIX=
IMAGE_VERSION=latest

# .secret file
DOCKERHUB_USERNAME=<your_name>
DOCKERHUB_TOKEN=<your_password>

# Create Docker containger from created image
#   -i      Keep STDIN open even if not attached
#   -t      Allocate a pseudo-TTY
#   --rm    Automatically remove the container when it exits
#   <image>:<version>
docker run -it --rm erriez/hello-alpine:latest
docker run -it --rm erriez/ubuntu-alpine:latest

# Show Docker images
docker images

# Remove hello image
docker rmi erriez/alpine-hello:latest
docker rmi erriez/ubuntu-hello:latest

Github Actions

# Configure secrets
Github project | Settings | Secrets | New Repository Secret...:
   DOCKER_ORG
   DOCKER_USERNAME
   DOCKER_PASSWORD

docker-buildx-multiarch-example's People

Contributors

erriez avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.