Dockerfile

Dockerfile type identification strategy

There are Dockerfile files in the main code directory, and Rainbond will recognize the code language type as Dockerfile . This policy has the highest priority. When the code conforms to other language type identification policies at the same time,Dockerfileis still the main one.

Compilation principle

The source code identified as Dockerfile type will use command similar to `docker build -t xxx/xxx. Docker support).

The build process supports docker multi-stage (multi-stage build) and ARG parameter specification.

Dockerfile specification

Dockerfile is a script consisting of a series of commands and parameters that are applied to the base image and ultimately create a new image.

Rainbond will read the following parameters defined in the Dockerfile during the source code detection stage

Parameter Typenameillustrate
ENVenvironment variableIdentify the environment variable configuration settable for the service
ARGbuild parametersIdentify the parameter configuration that can be set for the build
EXPOSEexposed portPort configuration identified as a service
VOLUMEpersistent storageShared persistent storage configuration identified as a service

For the definition of Dockerfile, please refer to the official document: https://docs.docker.com/engine/reference/builder/

Here is a use case for Dockerfile to compile and deploy Golang source code:

  1. FROM muninn/glide:alpine AS build-env
  2. ADD . /go/src/app
  3. WORKDIR /go/src/app
  4. RUN glide install
  5. RUN go build -v -o /go/src/app/app-server
  6. FROM alpine
  7. RUN apk add -U tzdata
  8. RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  9. COPY --from=build-env /go/src/app/app-server /usr/ local/bin/app-server
  10. EXPOSE 80
  11. CMD ["app-server"]

full sample code

How to deal with private repositories?

If your Dockerfile uses an image from a private image repository, when you build directly with this Dockerfile, you will not be able to pull the correct image for building due to permission issues.At this point, you can select the authorization information of the mirror warehouse in the team management, fill in the domain name, user name and password of the private mirror warehouse, save it and build it again, and the build will be successful.As shown below:

private-repo-dockerfile.png