docker: the docker image will now contain just the static binary

master
Krishna Srinivas 9 years ago
parent 8ef4ec24ca
commit 440bec28d9
  1. 16
      Docker.md
  2. 44
      Dockerfile
  3. 12
      Makefile
  4. 13
      main.go
  5. 29
      pkg/fs/config.go
  6. 5
      server-config.go
  7. 24
      utils.go

@ -0,0 +1,16 @@
# docker run
To run docker image:
```docker run -p 9000:9000 minio/minio:latest```
This will start minio server in the docker container, the data however is not persistent.
If you need persistent storage you can use the command:
```docker run -p 9000:9000 -v /home/krishna/.minio:/.minio -v /home/user/export:/export minio:latest```
Here the data uploaded to the minio server will be persisted to /home/user/export directory.
# docker build
To build the docker image:
```make dockerimage TAG="<tag>"```

@ -1,38 +1,8 @@
FROM ubuntu-debootstrap:14.04 # use "make dockerimage" to build
FROM scratch
MAINTAINER Minio Community ENV DOCKERIMAGE 1
ADD minio.dockerimage /minio
ENV GOLANG_TARBALL go1.5.1.linux-amd64.tar.gz ADD export /export
ENV GOROOT /usr/local/go/
ENV GOPATH /go-workspace
ENV PATH ${GOROOT}/bin:${GOPATH}/bin/:$PATH
ENV MINIOHOME /home/minio
ENV MINIOUSER minio
RUN useradd -m -d $MINIOHOME $MINIOUSER
RUN apt-get update -y && apt-get install -y -q \
curl \
git \
build-essential \
ca-certificates
RUN curl -O -s https://storage.googleapis.com/golang/${GOLANG_TARBALL} && \
tar -xzf ${GOLANG_TARBALL} -C ${GOROOT%*go*} && \
rm ${GOLANG_TARBALL}
ADD . ${GOPATH}/src/github.com/minio/minio
RUN cd ${GOPATH}/src/github.com/minio/minio && \
make
RUN apt-get remove -y build-essential curl git && \
apt-get -y autoremove && \
rm -rf /var/lib/apt/lists/*
USER minio
EXPOSE 9000 EXPOSE 9000
ENTRYPOINT ["/minio"]
CMD ["sh", "-c", "${GOPATH}/bin/minio server"] CMD ["server", "/export"]

@ -1,4 +1,6 @@
LDFLAGS = $(shell go run buildscripts/gen-ldflags.go) LDFLAGS = $(shell go run buildscripts/gen-ldflags.go)
DOCKER_LDFLAGS = '-extldflags "-static"'
TAG = latest
all: install all: install
@ -53,7 +55,7 @@ test: build
@GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) github.com/minio/minio/pkg... @GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) github.com/minio/minio/pkg...
gomake-all: build gomake-all: build
@GO15VENDOREXPERIMENT=1 go build -ldflags $(LDFLAGS) -o $(GOPATH)/bin/minio @GO15VENDOREXPERIMENT=1 go build --ldflags $(LDFLAGS) -o $(GOPATH)/bin/minio
pkg-add: pkg-add:
@GO15VENDOREXPERIMENT=1 govendor add $(PKG) @GO15VENDOREXPERIMENT=1 govendor add $(PKG)
@ -66,6 +68,14 @@ pkg-remove:
install: gomake-all install: gomake-all
dockerimage: install
@echo "Building docker image:" minio:$(TAG)
@GO15VENDOREXPERIMENT=1 go build --ldflags $(LDFLAGS) --ldflags $(DOCKER_LDFLAGS) -o minio.dockerimage
@mkdir -p export
@docker build --rm --tag=minio:$(TAG) .
@rmdir export
@rm minio.dockerimage
clean: clean:
@echo "Cleaning up all the generated files:" @echo "Cleaning up all the generated files:"
@rm -fv cover.out @rm -fv cover.out

@ -19,7 +19,6 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"os/user"
"runtime" "runtime"
"strconv" "strconv"
@ -29,18 +28,24 @@ import (
) )
func init() { func init() {
// Check if minio was compiled using a supported version of Golang.
checkGolangRuntimeVersion()
// Check for the environment early on and gracefuly report. // Check for the environment early on and gracefuly report.
_, err := user.Current() _, err := userCurrent()
if err != nil { if err != nil {
Fatalf("Unable to obtain user's home directory. \nError: %s\n", err) Fatalf("Unable to obtain user's home directory. \nError: %s\n", err)
} }
if os.Getenv("DOCKERIMAGE") == "1" {
// the further checks are ignored for docker image
return
}
if os.Geteuid() == 0 { if os.Geteuid() == 0 {
Fatalln("Please run ‘minio’ as a non-root user.") Fatalln("Please run ‘minio’ as a non-root user.")
} }
// Check if minio was compiled using a supported version of Golang.
checkGolangRuntimeVersion()
} }
func migrate() { func migrate() {

@ -17,6 +17,7 @@
package fs package fs
import ( import (
"os"
"os/user" "os/user"
"path/filepath" "path/filepath"
@ -24,13 +25,33 @@ import (
"github.com/minio/minio-xl/pkg/quick" "github.com/minio/minio-xl/pkg/quick"
) )
// workaround for docker images with fully static binary.
// for static binaries NSS library will not be a part of the static binary
// hence user.Current() fails
// more here : http://gnu.ist.utl.pt/software/libc/FAQ.html
// FAQ says : NSS (for details just type `info libc "Name Service Switch"') won't work properly without shared libraries
func userCurrent() (*user.User, *probe.Error) {
if os.Getenv("DOCKERIMAGE") == "1" {
wd, err := os.Getwd()
if err != nil {
return nil, probe.NewError(err)
}
return &user.User{Uid: "0", Gid: "0", Username: "root", Name: "root", HomeDir: wd}, nil
}
user, err := user.Current()
if err != nil {
return nil, probe.NewError(err)
}
return user, nil
}
func getFSBucketsConfigPath() (string, *probe.Error) { func getFSBucketsConfigPath() (string, *probe.Error) {
if customBucketsConfigPath != "" { if customBucketsConfigPath != "" {
return customBucketsConfigPath, nil return customBucketsConfigPath, nil
} }
u, err := user.Current() u, err := userCurrent()
if err != nil { if err != nil {
return "", probe.NewError(err) return "", err.Trace()
} }
fsBucketsConfigPath := filepath.Join(u.HomeDir, ".minio", "buckets.json") fsBucketsConfigPath := filepath.Join(u.HomeDir, ".minio", "buckets.json")
return fsBucketsConfigPath, nil return fsBucketsConfigPath, nil
@ -40,9 +61,9 @@ func getFSMultipartsSessionConfigPath() (string, *probe.Error) {
if customMultipartsConfigPath != "" { if customMultipartsConfigPath != "" {
return customMultipartsConfigPath, nil return customMultipartsConfigPath, nil
} }
u, err := user.Current() u, err := userCurrent()
if err != nil { if err != nil {
return "", probe.NewError(err) return "", err.Trace()
} }
fsMultipartsConfigPath := filepath.Join(u.HomeDir, ".minio", "multiparts-session.json") fsMultipartsConfigPath := filepath.Join(u.HomeDir, ".minio", "multiparts-session.json")
return fsMultipartsConfigPath, nil return fsMultipartsConfigPath, nil

@ -21,7 +21,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"os/user"
"path/filepath" "path/filepath"
"github.com/fatih/color" "github.com/fatih/color"
@ -124,9 +123,9 @@ func getConfigPath() (string, *probe.Error) {
if customConfigPath != "" { if customConfigPath != "" {
return customConfigPath, nil return customConfigPath, nil
} }
u, err := user.Current() u, err := userCurrent()
if err != nil { if err != nil {
return "", probe.NewError(err) return "", err.Trace()
} }
configPath := filepath.Join(u.HomeDir, ".minio") configPath := filepath.Join(u.HomeDir, ".minio")
return configPath, nil return configPath, nil

@ -18,8 +18,12 @@ package main
import ( import (
"encoding/base64" "encoding/base64"
"os"
"os/user"
"strconv" "strconv"
"strings" "strings"
"github.com/minio/minio-xl/pkg/probe"
) )
// isValidMD5 - verify if valid md5 // isValidMD5 - verify if valid md5
@ -51,3 +55,23 @@ func isMaxObjectSize(size string) bool {
} }
return false return false
} }
// workaround for docker images with fully static binary.
// for static binaries NSS library will not be a part of the static binary
// hence user.Current() fails
// more here : http://gnu.ist.utl.pt/software/libc/FAQ.html
// FAQ says : NSS (for details just type `info libc "Name Service Switch"') won't work properly without shared libraries
func userCurrent() (*user.User, *probe.Error) {
if os.Getenv("DOCKERIMAGE") == "1" {
wd, err := os.Getwd()
if err != nil {
return nil, probe.NewError(err)
}
return &user.User{Uid: "0", Gid: "0", Username: "root", Name: "root", HomeDir: wd}, nil
}
user, err := user.Current()
if err != nil {
return nil, probe.NewError(err)
}
return user, nil
}

Loading…
Cancel
Save