Sign in

Docker

Use a multistage Dockerfile.

A python example

FROM python:3.6-alpine as builder
ARG APP_VERSION

RUN apk add --update \
    make

# Add the code

WORKDIR /app
# Add files needed to install depencies
ADD Makefile README.md setup.py ./
# Install dependencies
RUN make configure APP_VERSION=${APP_VERSION}
# Add the code
ADD . .
# Build the codebase, will run tests etc
RUN make build APP_VERSION=${APP_VERSION}

FROM python:3.6-alpine
ARG APP_VERSION

# Copy the runtime artifact from the builder image
COPY --from=builder /app/dist /dist

# Install the runtime artifact
RUN pip install dist/application_name-${APP_VERSION}-py3-none-any.whl
RUN rm -rf dist

ENTRYPOINT [ "application_name" ]

Build the image and passing in the APP_VERSION.

docker build \
    -t application_name:latest \
    --build-arg APP_VERSION=0.0.1 \
    -f Dockerfile .

When using ENTRYPOINT your image acts more like a binary, You can pass it arguments like you would a binary.

docker run application_name:latest -h