ci.docker icon indicating copy to clipboard operation
ci.docker copied to clipboard

Is it known to be able to use buildx build to cross compile to amd64 on Apple Silicon?

Open edburns opened this issue 1 year ago • 1 comments

Consider this Dockerfile.

# DisableDockerDetector "liberty-maven-plugin does not support docker buildx-build. See https://github.com/OpenLiberty/ci.maven/issues/1589"
# open liberty base image
FROM icr.io/appcafe/open-liberty:23.0.0.3-kernel-slim-java17-openj9-ubi

# Use the ARG instruction to define the VERBOSE build argument
ARG VERBOSE=true

# Use the ENV instruction to define the VERBOSE environment variable
ENV VERBOSE=$VERBOSE


# Add config
COPY --chown=1001:0 liberty/wlp/usr/servers/defaultServer/server.xml /config/server.xml

# This script will add the requested XML snippets to enable Liberty features and grow image to be fit-for-purpose using featureUtility.
# Only available in 'kernel-slim'. The 'full' tag already includes all features for convenience.
RUN features.sh

# Add app and jdbc driver
COPY --chown=1001:0 javaee-cafe.war /config/apps/
COPY --chown=1001:0 liberty/wlp/usr/shared/resources/mssql-jdbc-8.2.2.jre8.jar /opt/ol/wlp/usr/shared/resources/

# This script will add the requested XML snippets, grow image to be fit-for-purpose and apply interim fixes
RUN configure.sh

The complete app from which this Dockerfile is taken is at https://github.com/azure-javaee/open-liberty-on-aks/blob/main/java-app/pom.xml . This app is the sample for this article: https://learn.microsoft.com/en-us/azure/aks/howto-deploy-java-liberty-app .

I observe if I try to build the container image with Docker Desktop for macOS 14.3.1 on Apple Silicon with this command:

docker buildx build --platform linux/amd64 -t javaee-cafe:v1 --pull --file=Dockerfile .

I see this failed result.

edburns@Edwards-MBP target % docker buildx build --platform linux/amd64 -t javaee-cafe:v1 --pull --file=Dockerfile .
[+] Building 14.7s (9/9) FINISHED                          docker:desktop-linux
 => [internal] load build definition from Dockerfile                       0.0s
 => => transferring dockerfile: 1.02kB                                     0.0s
 => [internal] load metadata for icr.io/appcafe/websphere-liberty:kernel-  0.1s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => [1/5] FROM icr.io/appcafe/websphere-liberty:kernel-java17-openj9-ubi@  0.0s
 => [internal] load build context                                          0.0s
 => => transferring context: 842B                                          0.0s
 => CACHED [2/5] COPY --chown=1001:0 liberty/wlp/usr/servers/defaultServe  0.0s
 => [3/5] COPY --chown=1001:0 javaee-cafe.war /config/apps/                0.0s
 => [4/5] COPY --chown=1001:0 liberty/wlp/usr/shared/resources/mssql-jdbc  0.0s
 => ERROR [5/5] RUN configure.sh                                          14.6s
------
 > [5/5] RUN configure.sh:
0.210 WARNING: This is not an optimal build configuration. Although features in server.xml will continue to be installed correctly, the 'RUN features.sh' command should be added to the Dockerfile prior to configure.sh. See https://ibm.biz/wl-app-image-template for a sample application image template.
0.224 + main
0.225 + WLP_INSTALL_DIR=/opt/ibm/wlp
0.226 + SHARED_CONFIG_DIR=/opt/ibm/wlp/usr/shared/config
0.226 + SHARED_RESOURCE_DIR=/opt/ibm/wlp/usr/shared/resources
0.226 + SNIPPETS_SOURCE=/opt/ibm/helpers/build/configuration_snippets
0.226 + SNIPPETS_TARGET=/config/configDropins/overrides
0.226 + SNIPPETS_TARGET_DEFAULTS=/config/configDropins/defaults
0.226 + mkdir -p /config/configDropins/overrides
0.250 + mkdir -p /config/configDropins/defaults
0.274 + '[' false == false ']'
0.275 + '[' '' == true ']'
0.275 + '[' '' == true ']'
0.275 + '[' '' == true ']'
0.275 + '[' '' == true ']'
0.275 + '[' '' == true ']'
0.275 + '[' '' == true ']'
0.275 + '[' '' == true ']'
0.275 + '[' '' == true ']'
0.275 + [[ -n '' ]]
0.276 + '[' '' == client ']'
0.276 + '[' '' == embedded ']'
0.276 + [[ -n '' ]]
0.276 + '[' '' == true ']'
0.276 + '[' '' == true ']'
0.276 + keystorePath=/config/configDropins/defaults/keystore.xml
0.276 + '[' '' '!=' false ']'
0.276 + '[' '' '!=' false ']'
0.277 + '[' '!' -e /config/configDropins/defaults/keystore.xml ']'
0.279 ++ openssl rand -base64 32
0.313 + export KEYSTOREPWD=KJUy1JgkRsrMrsR0hEB9EUIqI/pb/Z3sNTTxRWh0kFw=
0.313 + KEYSTOREPWD=KJUy1JgkRsrMrsR0hEB9EUIqI/pb/Z3sNTTxRWh0kFw=
0.313 + sed 's|REPLACE|KJUy1JgkRsrMrsR0hEB9EUIqI/pb/Z3sNTTxRWh0kFw=|g' /opt/ibm/helpers/build/configuration_snippets/keystore.xml
0.345 + chmod g+w /config/configDropins/defaults/keystore.xml
0.368 + [[ -n '' ]]
0.368 + '[' '' '!=' true ']'
0.368 + '[' false == false ']'
0.368 + '[' '' ']'
0.368 + installUtility install --acceptLicense defaultServer
2.904 Checking for missing features required by the server ...
3.254 Establishing a connection to the configured repositories ...
3.254 This process might take several minutes to complete.
3.254
7.329 Successfully connected to all configured repositories.
7.329
7.331 Preparing assets for installation. This process might take several minutes to complete.
14.57 qemu: uncaught target signal 11 (Segmentation fault) - core dumped
14.58 /opt/ibm/wlp/bin/installUtility: line 185:    40 Segmentation fault      "${JAVA_CMD}" "$@"
14.58 + rc=139
14.58 + '[' 139 -ne 22 ']'
14.58 + exit 139
------
Dockerfile:23
--------------------
  21 |
  22 |     # This script will add the requested XML snippets, grow image to be fit-for-purpose and apply interim fixes
  23 | >>> RUN configure.sh
  24 |
--------------------

edburns avatar Feb 26 '24 17:02 edburns

Hi Ed, you might be running into this problem : https://github.com/docker/for-mac/issues/7180

mingcyu avatar Feb 26 '24 19:02 mingcyu

Hello @mingcyu , I confirm that after updating to a version of Docker for Desktop macOS, the problem went away.

edburns avatar Apr 02 '24 18:04 edburns