question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(assets): allow user to pass platform option to Docker builds

See original GitHub issue

Use Case

To be able to build images for amd64 architecture (e.g. AWS Fargate) on a system that is using other architecture like arm64 (e.g. Apple M1).

Proposed Solution

Replace docker build with docker buildx build.

https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images

With buildx you can build cross-platform images by declaring --platform argument. e.g. docker buildx build --platform linux/amd64 someimage:sometag . executed on system Apple M1 results in an image which works system with amd64 architecture.

buildx allows you also to build image for multiple platforms at once. e.g. --platform linux/amd64,linux/arm64

Other

Currently image .fromAsset results in an image that works only on the same architecture where it was built. In that sense, this could be considered also a bug – the image built doesn’t work on the target system (Fargate).

import { FargateTaskDefinition, ContainerImage } from '@aws-cdk/aws-ecs';

const taskDefinition = new FargateTaskDefinition(this, 'TaskDefinition');

taskDefinition
  .addContainer('Container', {
    image: ContainerImage.fromAsset(path.resolve(__dirname, '../image')),
  });
  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:61
  • Comments:31 (18 by maintainers)

github_iconTop GitHub Comments

36reactions
lmamminocommented, Aug 15, 2021

One solution that I found (after much head banging 🙉 ) is to put --platform ... in the FROM instruction at the beginning of my Dockerfile:

FROM --platform=linux/amd64 someBaseImage:someVersion
# ... moar cool docker stuff here 🐳

You could also use a build arg to specify an arbitrary value for platform or create different target images for different platforms you need to support.

I hope this helps 😃

32reactions
arektcommented, Jul 5, 2021

Just a note for people with M1 chip. Docker supports DOCKER_DEFAULT_PLATFORM=‘linux/amd64’ env variable now. https://docs.docker.com/engine/reference/commandline/cli/

Read more comments on GitHub >

github_iconTop Results From Across the Web

class DockerImageAsset (construct) · AWS CDK
An asset that represents a Docker image. The image will be created in build time and uploaded to an ECR repository. Example. import...
Read more >
Multi-Platform Docker Builds
Let's start by looking at the first option, emulation. There's a fantastic project called QEMU that can emulate a whole bunch of platforms....
Read more >
App Platform Dockerfile Build Reference
To pass environment variables to a Dockerfile-based resource, define them as build-time or run-time environment variables in App Platform. This passes variables ...
Read more >
Build Strategy Options | OpenShift Container Platform 3.11
The dockerfilePath field allows the build to use a different path to locate your Dockerfile, relative to the BuildConfig.spec.source.contextDir field.
Read more >
Container Images - Quarkus
push unset - it defaults to false ), then this extension creates a container image and registers it with the Docker daemon. This...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found