Answers: <p>-<code>--build-arg       Set build-time variables</code> it is possible to build with arch parameter depending on this arch is whether host arch or docker image arch.</p>
  
Answers: CC BY-SA 4.0
Answers: 2021-12-27T06:55:27.447Z
Answers: 2021-12-27T06:55:27.447Z
Answers: hakkican
Answers: <p>It would be hacky, but you could <code>sed</code> it in with a wrapper script.</p>
  <pre><code>#! /usr/bin/env bash
  
  platform=$(uname -p)
  
  if [[ $platform == &quot;arm64&quot; ]]; then
      sed -i 's/FROM swift\:5\.5\.2/FROM swiftarm\/swift/' Dockerfile
  fi
  
  docker build ...
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-12-21T03:02:32.720Z
Answers: 2021-12-21T03:02:32.720Z
Answers: Deuce
Body: <p>I have a somewhat specific, Swift-based problem.<br />
  It seems that none of the official Swift images on Dockerhub support the M1, and instead the only seemingly reliable arm64 Swift images are found at swiftarm/swift. This means that manifest querying will always fail for an M1 for something like <code>FROM swift:5.5.2</code>. Additionally, trying to get around this with <code>--platform=x86_64</code> the particular project I'm trying to run fails to compile due to an error with the Swift compiler in QEMU.<br />
  Is there a way to do something like</p>
  <pre><code>IF platform == arm64 FROM swiftarm/swift
  ELSE FROM swift:5.5.2
  </code></pre>
  <p>or should I just build and push my own multiplatform image</p>
  
Tags: <dockerfile><macos>
Title: Specify image in Dockerfile based on building client platform/architecture
UserDisplayName: JMA
ThreadText: # Specify image in Dockerfile based on building client platform/architecture
  
  (Asked by: username_0 on 2021-12-20)
  
  I have a somewhat specific, Swift-based problem.  
  It seems that none of the official Swift images on Dockerhub support the M1, and instead the only seemingly reliable arm64 Swift images are found at swiftarm/swift. This means that manifest querying will always fail for an M1 for something like `FROM swift:5.5.2`. Additionally, trying to get around this with `--platform=x86_64` the particular project I'm trying to run fails to compile due to an error with the Swift compiler in QEMU.  
  Is there a way to do something like
  
  ```
  IF platform == arm64 FROM swiftarm/swift
  ELSE FROM swift:5.5.2
  
  ```
  
  or should I just build and push my own multiplatform image
  
  **Tags:** dockerfile, macos
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-12-27. Score: 1
  
  -`--build-arg Set build-time variables` it is possible to build with arch parameter depending on this arch is whether host arch or docker image arch.
  
  
  ---
  
  ### Answer by username_2 on 2021-12-21. Score: 0
  
  It would be hacky, but you could `sed` it in with a wrapper script.
  
  ```
  #! /usr/bin/env bash
  
  platform=$(uname -p)
  
  if [[ $platform == "arm64" ]]; then
      sed -i 's/FROM swift\:5\.5\.2/FROM swiftarm\/swift/' Dockerfile
  fi
  
  docker build ...
  
  ```
  
  
  ---
  
  