Created
April 25, 2018 12:11
-
-
Save Maecenas/3f6fcf450ecd19d92b9fe2f19cf7e64c to your computer and use it in GitHub Desktop.
Dockerfile best practices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dockerfile-1 | |
FROM golang:1.9-alpine | |
RUN apk --no-cache add git ca-certificates | |
WORKDIR /go/src/github.com/go/helloworld/ | |
COPY app.go . | |
RUN go get -d -v github.com/go-sql-driver/mysql \ | |
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . \ | |
&& cp /go/src/github.com/go/helloworld/app /root | |
WORKDIR /root/ | |
CMD ["./app"] | |
# Dockerfile-2a | |
FROM golang:1.9-alpine | |
RUN apk --no-cache add git | |
WORKDIR /go/src/github.com/go/helloworld | |
COPY app.go . | |
RUN go get -d -v github.com/go-sql-driver/mysql \ | |
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . | |
# Dockerfile-2b | |
FROM alpine:latest | |
RUN apk --no-cache add ca-certificates | |
WORKDIR /root/ | |
COPY app . | |
CMD ["./app"] | |
# run.sh-2c | |
#!/bin/sh | |
echo Building go/helloworld:build | |
docker build -t go/helloworld:build . -f Dockerfile.build | |
docker create --name extract go/helloworld:build | |
docker cp extract:/go/src/github.com/go/helloworld/app ./app | |
docker rm -f extract | |
echo Building go/helloworld:2 | |
docker build --no-cache -t go/helloworld:2 . -f Dockerfile.copy | |
rm ./app | |
# Dockerfile-3 | |
FROM golang:1.9-alpine as builder | |
RUN apk --no-cache add git | |
WORKDIR /go/src/github.com/go/helloworld/ | |
RUN go get -d -v github.com/go-sql-driver/mysql | |
COPY app.go . | |
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . | |
FROM alpine:latest as prod | |
RUN apk --no-cache add ca-certificates | |
WORKDIR /root/ | |
# Copy file from last image | |
# COPY --from=nginx:latest /etc/nginx/nginx.conf /nginx.conf | |
COPY --from=0 /go/src/github.com/go/helloworld/app . | |
CMD ["./app"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dockerfile-1 | |
FROM node:slim | |
RUN mkdir /app | |
WORKDIR /app | |
COPY ./package.json /app | |
RUN [ "npm", "install" ] | |
COPY . /app/ | |
CMD [ "npm", "start" ] | |
# mynode-2 | |
FROM node:slim | |
RUN mkdir /app | |
WORKDIR /app | |
CMD [ "npm", "start" ] | |
# Dockerfile-2 | |
FROM my-node | |
COPY ./package.json /app | |
RUN [ "npm", "install" ] | |
COPY . /app/ | |
# mynode-3 | |
FROM node:slim | |
RUN mkdir /app | |
WORKDIR /app | |
ONBUILD COPY ./package.json /app | |
ONBUILD RUN [ "npm", "install" ] | |
ONBUILD COPY . /app/ | |
CMD [ "npm", "start" ] | |
# Dockerfile-3 | |
FROM my-node |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment