Linux — Docker

https://docs.docker.com/

基础概念 #

scratch 镜像是一个空的镜像文件,适合通过 scratch 来构建一个基础镜像,也特别适合创建超级小的镜像。

命令行 #

打包 #

docker build example.

各语言打包举例 #

Golang #

FROM golang:1.12.17 AS build-env
ADD . /go/src/gitlab.com/tcitry/gogogo
WORKDIR /go/src/gitlab.com/tcitry/gogogo

RUN go build -o /build/gogogo main.go

FROM golang:1.12.17
COPY --from=build-env /build/gogogo /data/src/
COPY conf/test.toml /data/src/
COPY entrypoint.sh /data/src/
EXPOSE 5555

ENTRYPOINT ["/data/src/entrypoint.sh"]
#!/bin/sh

mv test.toml config.toml
if [ -z $COMMAND ]; then
if [ ! -z $1 ] ; then
COMMAND=$@
fi
exec /data/src/gogogo $COMMAND
else
exec /data/src/gogogo $COMMAND
fi

Python #


FROM python:3.6

WORKDIR /data/src

COPY ./requirements.txt /data/src/requirements.txt

RUN pip3 install -r requirements.txt
COPY . /data/src
COPY .env.example .env
COPY ./docker-entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
#!/bin/bash
case "$1" in
runserver)
exec python3 manage.py "$@"
;;
esac

if [ -z $1 ] ; then
exec gunicorn -b 0.0.0.0:8000 -w 4 -t 90 -p /var/run/project.pid project.wsgi:application
fi
本文共 182 字,上次修改于 Mar 8, 2024
相关标签: Linux