示例:
#Makefile
DOCKER ?= docker
MKDIR ?= mkdir
VERSION := 2.2.1
RUNTIME_VERSION := 3.1.2
PKG_REV := 1
DIST_DIR := $(CURDIR)/dist
.NOTPARALLEL:
.PHONY: all
all: ubuntu18.04 ubuntu16.04 debian10 debian9 centos7 amzn2 amzn1 opensuse-leap15.1
ubuntu18.04: ARCH := amd64
ubuntu18.04:
$(DOCKER) build --build-arg VERSION_ID="18.04" --build-arg DOCKER_VERSION="docker-ce (>= 18.06.0~ce~3-0~ubuntu) | docker-ee (>= 18.06.0~ce~3-0~ubuntu) | docker.io (>= 18.06.0)" --build-arg RUNTIME_VERSION="$(RUNTIME_VERSION)" --build-arg PKG_VERS="$(VERSION)" --build-arg PKG_REV="$(PKG_REV)" -t "nvidia/nvidia-docker2/ubuntu:18.04" -f Dockerfile.ubuntu .
$(MKDIR) -p $(DIST_DIR)/ubuntu18.04/$(ARCH)
$(DOCKER) run --cidfile $@.cid "nvidia/nvidia-docker2/ubuntu:18.04"
$(DOCKER) cp $$(cat $@.cid):/dist/. $(DIST_DIR)/ubuntu18.04/$(ARCH)
$(DOCKER) rm $$(cat $@.cid) && rm $@.cid
ubuntu16.04: ARCH := amd64
ubuntu16.04:
$(DOCKER) build --build-arg VERSION_ID="16.04" --build-arg DOCKER_VERSION="docker-ce (>= 18.06.0~ce~3-0~ubuntu) | docker-ee (>= 18.06.0~ce~3-0~ubuntu) | docker.io (>= 18.06.0)" --build-arg RUNTIME_VERSION="$(RUNTIME_VERSION)" --build-arg PKG_VERS="$(VERSION)" --build-arg PKG_REV="$(PKG_REV)" -t "nvidia/nvidia-docker2/ubuntu:16.04" -f Dockerfile.ubuntu .
$(MKDIR) -p $(DIST_DIR)/ubuntu16.04/$(ARCH)
$(DOCKER) run --cidfile $@.cid "nvidia/nvidia-docker2/ubuntu:16.04"
$(DOCKER) cp $$(cat $@.cid):/dist/. $(DIST_DIR)/ubuntu16.04/$(ARCH)
$(DOCKER) rm $$(cat $@.cid) && rm $@.cid
debian10: ARCH := amd64
debian10:
$(DOCKER) build --build-arg VERSION_ID="10" --build-arg DOCKER_VERSION="docker-ce (>= 18.06.0~ce~3-0~debian) | docker-ee (>= 18.06.0~ce~3-0~debian) | docker.io (>= 18.06.0)" --build-arg RUNTIME_VERSION="$(RUNTIME_VERSION)" --build-arg PKG_VERS="$(VERSION)" --build-arg PKG_REV="$(PKG_REV)" -t "nvidia/nvidia-docker2/debian:10" -f Dockerfile.debian .
$(MKDIR) -p $(DIST_DIR)/debian10/$(ARCH)
$(DOCKER) run --cidfile $@.cid "nvidia/nvidia-docker2/debian:10"
$(DOCKER) cp $$(cat $@.cid):/dist/. $(DIST_DIR)/debian10/$(ARCH)
$(DOCKER) rm $$(cat $@.cid) && rm $@.cid
debian9: ARCH := amd64
debian9:
$(DOCKER) build --build-arg VERSION_ID="9" --build-arg DOCKER_VERSION="docker-ce (>= 18.06.0~ce~3-0~debian) | docker-ee (>= 18.06.0~ce~3-0~debian) | docker.io (>= 18.06.0)" --build-arg RUNTIME_VERSION="$(RUNTIME_VERSION)" --build-arg PKG_VERS="$(VERSION)" --build-arg PKG_REV="$(PKG_REV)" -t "nvidia/nvidia-docker2/debian:9" -f Dockerfile.debian .
$(MKDIR) -p $(DIST_DIR)/debian9/$(ARCH)
$(DOCKER) run --cidfile $@.cid "nvidia/nvidia-docker2/debian:9"
$(DOCKER) cp $$(cat $@.cid):/dist/. $(DIST_DIR)/debian9/$(ARCH)
$(DOCKER) rm $$(cat $@.cid) && rm $@.cid
centos7: ARCH := x86_64
centos7:
$(DOCKER) build --build-arg VERSION_ID="7" --build-arg DOCKER_VERSION="docker-ce >= 18.06.3.ce-3.el7" --build-arg RUNTIME_VERSION="$(RUNTIME_VERSION)" --build-arg PKG_VERS="$(VERSION)" --build-arg PKG_REV="$(PKG_REV)" -t "nvidia/nvidia-docker2/centos:7" -f Dockerfile.centos .
$(MKDIR) -p $(DIST_DIR)/centos7/$(ARCH)
$(DOCKER) run --cidfile $@.cid "nvidia/nvidia-docker2/centos:7"
$(DOCKER) cp $$(cat $@.cid):/dist/. $(DIST_DIR)/centos7/$(ARCH)
$(DOCKER) rm $$(cat $@.cid) && rm $@.cid
amzn2: ARCH := x86_64
amzn2:
$(DOCKER) build --build-arg VERSION_ID="2" --build-arg DOCKER_VERSION="docker >= 18.06.1ce-2.amzn2" --build-arg RUNTIME_VERSION="$(RUNTIME_VERSION)" --build-arg PKG_VERS="$(VERSION)" --build-arg PKG_REV="$(PKG_REV)" -t "nvidia/nvidia-docker2/amzn:2-docker" -f Dockerfile.amzn .
$(MKDIR) -p $(DIST_DIR)/amzn2/$(ARCH)
$(DOCKER) run --cidfile $@.cid "nvidia/nvidia-docker2/amzn:2-docker"
$(DOCKER) cp $$(cat $@.cid):/dist/. $(DIST_DIR)/amzn2/$(ARCH)
$(DOCKER) rm $$(cat $@.cid) && rm $@.cid
amzn1: ARCH := x86_64
amzn1:
$(DOCKER) build --build-arg VERSION_ID="1" --build-arg DOCKER_VERSION="docker >= 18.06.1ce-2.16.amzn1" --build-arg RUNTIME_VERSION="$(RUNTIME_VERSION)" --build-arg PKG_VERS="$(VERSION)" --build-arg PKG_REV="$(PKG_REV)" -t "nvidia/nvidia-docker2/amzn:1" -f Dockerfile.amzn .
$(MKDIR) -p $(DIST_DIR)/amzn1/$(ARCH)
$(DOCKER) run --cidfile $@.cid "nvidia/nvidia-docker2/amzn:1"
$(DOCKER) cp $$(cat $@.cid):/dist/. $(DIST_DIR)/amzn1/$(ARCH)
$(DOCKER) rm $$(cat $@.cid) && rm $@.cid
opensuse-leap15.1: ARCH := x86_64
opensuse-leap15.1:
$(DOCKER) build --build-arg VERSION_ID="15.1" --build-arg DOCKER_VERSION="docker >= 18.09.1_ce" --build-arg RUNTIME_VERSION="$(RUNTIME_VERSION)" --build-arg PKG_VERS="$(VERSION)" --build-arg PKG_REV="$(PKG_REV)" -t "nvidia/nvidia-docker2/opensuse-leap:15.1" -f Dockerfile.opensuse-leap .
$(MKDIR) -p $(DIST_DIR)/opensuse-leap15.1/$(ARCH)
$(DOCKER) run --cidfile $@.cid "nvidia/nvidia-docker2/opensuse-leap:15.1"
$(DOCKER) cp $$(cat $@.cid):/dist/. $(DIST_DIR)/opensuse-leap15.1/$(ARCH)
$(DOCKER) rm $$(cat $@.cid) && rm $@.cid
##dockerfile Dockerfile.centos
ARG VERSION_ID
FROM centos:${VERSION_ID}
# packaging dependencies
RUN yum install -y rpm-build && rm -rf /var/cache/yum/*
# packaging
ARG PKG_VERS
ARG PKG_REV
ARG RUNTIME_VERSION
ARG DOCKER_VERSION
ENV VERSION $PKG_VERS
ENV RELEASE $PKG_REV
ENV DOCKER_VERSION $DOCKER_VERSION
ENV RUNTIME_VERSION $RUNTIME_VERSION
# output directory
ENV DIST_DIR=/tmp/nvidia-container-runtime-$PKG_VERS/SOURCES
RUN mkdir -p $DIST_DIR /dist
COPY nvidia-docker $DIST_DIR
COPY daemon.json $DIST_DIR
WORKDIR $DIST_DIR/..
COPY rpm .
RUN sed -i "s;@VERSION@;${PKG_VERS};" $DIST_DIR/nvidia-docker
CMD rpmbuild --clean -bb -D "_topdir $PWD" -D "version $VERSION" -D "release $RELEASE" -D "docker_version $DOCKER_VERSION" -D "runtime_version $RUNTIME_VERSION" SPECS/nvidia-docker2.spec && mv RPMS/noarch/*.rpm /dist
声明变量
name=ryan
声明规则Rule
Makefile文件由一系列规则(rules)构成。每条规则的形式如下
<target> : <prerequisites>
[tab] <commands>
target 目标
prerequisites 前置条件
tab command必须由tab隔开
commands 只能有一行的shell
防止target和文件名一样
当我们设置的target和当前目录下的文件名一样的话,target会被忽略,所以,通常,我们把target都用做phony target。
.PHONY: build start push
表示, build start push 这3个target,不检查当前目录下的文件,直接执行命令。
#示例Makefile
NAME = ryan/airflow
VERSION = 1.10.4
.PHONY: build start push
build: build-version
build-version:
docker build -t ${NAME}:${VERSION} .
tag-latest:
docker tag ${NAME}:${VERSION} ${NAME}:latest
start:
docker run -it --rm ${NAME}:${VERSION} /bin/bash
push: build-version tag-latest
docker push ${NAME}:${VERSION}; docker push ${NAME}:latest
构建一个版本的镜像
make build
构建完毕,运行一下镜像,看看内容是否正确
make start
最后推送到docker仓库
make push
https://gitlab.com/nvidia/container-images/cuda/blob/master/dist/centos7/9.0/base/Dockerfile
FROM centos:7
LABEL maintainer "NVIDIA CORPORATION <sw-cuda-installer@nvidia.com>"
RUN NVIDIA_GPGKEY_SUM=d1be581509378368edeec8c1eb2958702feedf3bc3d17011adbf24efacce4ab5 && curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/7fa2af80.pub | sed ‘/^Version/d‘ > /etc/pki/rpm-gpg/RPM-GPG-KEY-NVIDIA && echo "$NVIDIA_GPGKEY_SUM /etc/pki/rpm-gpg/RPM-GPG-KEY-NVIDIA" | sha256sum -c --strict -
COPY cuda.repo /etc/yum.repos.d/cuda.repo
ENV CUDA_VERSION 10.1.243
ENV CUDA_PKG_VERSION 10-1-$CUDA_VERSION-1
# For libraries in the cuda-compat-* package: https://docs.nvidia.com/cuda/eula/index.html#attachment-a
RUN yum install -y cuda-cudart-$CUDA_PKG_VERSION cuda-compat-10-1 && ln -s cuda-10.1 /usr/local/cuda && rm -rf /var/cache/yum/*
# nvidia-docker 1.0
RUN echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf && echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf
ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH}
ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64
# nvidia-container-runtime
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
ENV NVIDIA_REQUIRE_CUDA "cuda>=10.1 brand=tesla,driver>=384,driver<385 brand=tesla,driver>=396,driver<397 brand=tesla,driver>=410,driver<411"
原文:https://www.cnblogs.com/g2thend/p/12745091.html