(assets): allow user to pass platform option to Docker builds
See original GitHub issueUse 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:
- Created 3 years ago
- Reactions:61
- Comments:31 (18 by maintainers)
Top GitHub Comments
One solution that I found (after much head banging 🙉 ) is to put
--platform ...
in theFROM
instruction at the beginning of myDockerfile
: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 😃
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/