Dockerfile文件实例¶
实例:
# This is a comment
FROM ubuntu:14.04
MAINTAINER Kate Smith <ksmith@example.com>
RUN apt-get update && apt-get install -y ruby ruby-dev
RUN gem install sinatra
实例-时区:
实例1:
// 前提宿主机有文件/usr/share/zoneinfo/Asia/Shanghai
// 使用docker镜像的, 要求镜像有此文件
RUN copy /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
实例2:
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
实例:
1# Nginx
2#
3# VERSION 0.0.1
4
5FROM ubuntu
6MAINTAINER Victor Vieux <victor@docker.com>
7
8RUN apt-get update && apt-get install -y inotify-tools nginx apache2 openssh-server
9
10# Firefox over VNC
11#
12# VERSION 0.3
13
14FROM ubuntu
15
16# Install vnc, xvfb in order to create a 'fake' display and firefox
17RUN apt-get update && apt-get install -y x11vnc xvfb firefox
18RUN mkdir /.vnc
19# Setup a password
20RUN x11vnc -storepasswd 1234 ~/.vnc/passwd
21# Autostart firefox (might not be the best way, but it does the trick)
22RUN bash -c 'echo "firefox" >> /.bashrc'
23
24EXPOSE 5900
25CMD ["x11vnc", "-forever", "-usepw", "-create"]
26
27# Multiple images example
28#
29# VERSION 0.1
30
31FROM ubuntu
32RUN echo foo > bar
33# Will output something like ===> 907ad6c2736f
34
35FROM ubuntu
36RUN echo moo > oink
37# Will output something like ===> 695d7793cbe4
38
39# You now have two images, 907ad6c2736f with /bar, and 695d7793cbe4 with
40# /oink.
41
42
格式¶
一个镜像编译一个镜像发布¶
实例:
1
2# build step
3FROM golang:1.12 as builder
4
5LABEL maintainer="sunnydog0826@gmail.com"
6
7COPY . /build/
8
9WORKDIR /build
10
11RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build .
12
13# run step
14FROM alpine
15
16RUN apk update \
17 && apk add --no-cache ca-certificates \
18 && rm -rf /var/cache/apk/*
19
20# copy bin from build step
21COPY --from=builder /build/drone-dingtalk-message /bin/
22
23ENTRYPOINT ["/bin/drone-dingtalk-message"]