smac89
smac89

Reputation: 43234

32bit docker image with other images applied to it

I have a Dockerfile with the following:

FROM i386/alpine

WORKDIR /tmp/src/mybuild

ADD . /tmp/src/mybuild

FROM travisci/travis-build

My goal is to end up with a 32 bit image which contains the stuff from both images. After running sudo docker build --rm --tag travis-32 ., the "image" is built, but when I run sudo docker run -it travis-32 /bin/bash, I end up in a bash terminal and typing uname -m gives me x86_64, which is clearly not 32 bit as I was expecting.

How can I make this work?

Upvotes: 0

Views: 1388

Answers (1)

Ammar
Ammar

Reputation: 1314

what's wrong with the Dockerfile:

The Dokcerfile mentioned in the question is a multi-stage build file. Every stage starts with FROM, where one is supposed to copy the artifacts from the first build stage into the second, in the goal to achieve a smaller docker image to use in production at the end.

in the mentioned Dokcerfile:

  • the first stage copies some files to an i386/alpine image:
FROM i386/alpine
WORKDIR /tmp/src/mybuild
ADD . /tmp/src/mybuild
  • then everything done is ignored, and another image is taken instead:
FROM travisci/travis-build

so the end result is an exact copy of travisci/travis-build.

Regarding the 32b,64b question:

Usually what is compiled under 32b works only under 32b, and in order for it to run under 64b, you need to compile it under 64b (except for some languages like go, where you can define the target platform), so one need to be careful.

Example:

Take a look, and notice where the artifacts are moved from stage to another using the COPY --from= statement:

FROM golang:1.7.3 as builder
WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v golang.org/x/net/html  
COPY app.go    .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .

FROM alpine:latest  
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /go/src/github.com/alexellis/href-counter/app .
CMD ["./app"] 

More info can be found in the official docs: docker multistage-builds

hope this helps.

Upvotes: 1

Related Questions