I am trying to build the following image out of a Dockerfile.
Dockerfile source#
https://github.com/AykutSarac/jsoncrack.com/blob/main/Dockerfile
Docker host machine spec:
Macbook Pro M1 chip
I checked the following post:
standard_init_linux.go:178: exec user process caused "exec format error"
I added on the top extra lines:
#!/bin/bash
# Build for AMD64
# Builder
FROM node:14-buster as builder
WORKDIR /src
COPY . /src
RUN yarn install --legacy-peer-deps
RUN yarn run build
# App
FROM nginxinc/nginx-unprivileged
COPY --from=builder /src/out /app
COPY default.conf /etc/nginx/conf.d/default.conf
And then I created the image using the following commmand:
docker build -t username/jsoncrack-1-amd64 . --no-cache=true --platform=linux/amd64
Still showing the image when is pushed as arm type not
Any ideas on how to get that image built as Linux/AMD64 out of that Dockerfile?
Note: I am able to create other docker images on the M1 Apple Macbook without issues, the issue is only with this dockerfile.
Thanks
Actually I had to delete older images that would match the image build which end up pushing the older version ARM, not AMD.
Everything is working as expected with the steps above (Just make sure to clean your local stored images)
Related
I'm starting the "get-started" guide from official Docker website. At the Part 4 "Share the application", I'm facing this error message when I try to run my image on the docker hub from play-with-docker.com.
WARNING: The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested
I built the image from my apple M1 laptop:
FROM node:12-alpine
# Adding build tools to make yarn install work on Apple silicon / arm64 machines
RUN apk add --no-cache python2 g++ make
WORKDIR /app
COPY . .
RUN yarn install --producti
CMD ["node", "src/index.js"]
If you want to run the image on a linux/amd64 platform, you need to build it for that platform. You can do that with docker buildx like this and specify both your platforms
docker buildx build --platform linux/amd64,linux/arm64 -t <tag> .
I had the same error as srevinu as I was also using the tutorial which points to using the docker playground.
This sequence will build and push to docker hub so that it can be run on docker playground.
On your osx arm based computer docker buildx build --platform linux/amd64,linux/arm64 -t <YOUR_DOCKERHUB_ID/getting-started --push .
(If it gives an error and suggestion about issuing a docker buildx create --use, enter the command verbatim.)
After this command in tags pane on docker hub, you should see two platforms listed for the image. One image for linux/amd64 and one for linux/arm64.
On docker playground in the instance, docker run -dp 3000:3000 --platform linux/amd64 johndavis940/getting-started
The image will run and the port icon will be functional.
I am trying to make my application work in a Linux container. It will eventually be deployed to Azure Container Instances. I have absolutely no experience with containers what so ever and I am getting lost in the documentation and examples.
I believe the first thing I need to do is create a Docker image for my project. I have installed Docker Desktop.
My project has this structure:
MyProject
MyProject.Core
MyProject.Api
MyProject.sln
Dockerfile
The contents of my Dockerfile is as follows.
#Use Ubuntu Linux as base
FROM ubuntu:22.10
#Install dotnet6
RUN apt-get update && apt-get install -y dotnet6
#Install LibreOffice
RUN apt-get -y install default-jre-headless libreoffice
#Copy the source code
WORKDIR /MyProject
COPY . ./
#Compile the application
RUN dotnet publish -c Release -o /compiled
#ENV PORT 80
#Expose port 80
EXPOSE 80
ENTRYPOINT ["dotnet", "/compiled/MyProject.Api.dll"]
#ToDo: Split build and deployment
Now when I try to build the image using command prompt I am using the following command
docker build - < Dockerfile
This all processed okay up until the dotnet publish command where it errors saying
Specify a project or solution file
Now I have verified that this command works fine when run outside of the docker file. I suspect something is wrong with the copy? Again I have tried variations of paths for the WORKDIR, but I just can't figure out what is wrong.
Any advice is greatly appreciated.
Thank you SiHa in the comments for providing a solution.
I made the following change to my docker file.
WORKDIR app
Then I use the following command to build.
docker build -t ImageName -f FileName .
The image now creates successfully. I am able to run this in a container.
Whenever I run the following command to create a Docker image,
docker build -t ehi-member-portal:v1.0.0 -f ./Dockerfile .
I get the following results
I'm not sure why it is complaining about Node version because I am currently running
And I am not sure why it is detecting v12.14.1 when you see I am running v14.20.0. I installed Node and NPM using NVM. I used this site as a reference to how to create the node and ngix image for a container.
Here is the contents of my Dockerfile:
FROM node:12.14-alpine AS builder
WORKDIR /dist/src/app
RUN npm cache clean --force
COPY . .
RUN npm install
RUN npm run build --prod
FROM nginx:latest AS ngi
COPY --from=builder /dist/ehi-member-portal /usr/share/nginx/html
COPY /nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
Here is more version information:
Any help would be HIGHLY appreciated. I need to figure this out.
RUN npm run build --prod is executed INSIDE the docker container, and node inside is not in required version.
Also you clearly states that you want to use node v12 with
FROM node:12.14-alpine AS builder
so this is why it is "detected" as 12 because this is the node version inside the container. Bump the version. You can use some of images listed here
https://hub.docker.com/_/node
eg
FROM node:14.20.0-alpine AS builder
I just got started with docker and was following fireship's tutorial, however I encountered a problem when I ran the docker build command. I was expecting a similar output as the video (timestamp). Instead, I got the following:
Dockerfile
FROM node:12
WORKDIR /app #maybe its this? There is no /app directory
COPY package*.json ./
RUN npm install
COPY . .
ENV PORT=8080
EXPOSE 8080
CMD ["npm","start"]
docker build command
docker build -t <my docker id>/firstapp:1.1 .
File tree
D:/
Code/
testing/
Docker/
test1/
Notes
Yes, I have a docker ID.
The docker build command stopped at COPY . ., rather than finishing at CMD ["npm","start"]
CWD (Windows): D:\Code\testing\Docker\test1
I ran the docker build command twice
Questions
Why is this happening?
How can it be fixed?
The reason this occurs is because fireship is running Linux (like Hans Kilian noted) and I am running Windows. To get your image ID, run the docker images command, which will list your images w/ their image ID.
However, I am still not sure why it does not complete all 8 steps.
I tried to create a docker image based on alpine, but whenever I try to run it, I get this error message: standard_init_linux.go:219: exec user process caused: exec format error.
Here's the basic Dockerfile that just runs an executable file:
FROM alpine:3.13.5
WORKDIR /usr/local/bin
COPY profiles-svc /usr/local/bin
EXPOSE 20002/tcp
ENTRYPOINT ["/usr/local/bin/profiles-svc"]
The profiles-svc is an executable generated by the go build command.
I did not notice this issue on my ubuntu laptop, happens only on the Macbook M1.
Thanks in advance for the help!
The issue was that there are two different architectures. If you use go build command on M1, it will be arm64, so if you try to execute that on docker with, for example, alpine image, it will fail. To fix that issue, you need to build amd64 based binary. Here's the command: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o out-amd64. Now you can copy that binary to your Linux based dockerfile, build and run.
This is happening because the golang code compiled under Linux arm platform cannot be run under Linux amd platfrom; Similarly, the image built under arm platform will not run on amd platform. The solution is to add the — platform Linux/AMD64 parameter when building your images.
docker build --platform linux/amd64 -t tag .