docker: Add dockerfiles for running dcrd nodes.

This removes existing dockerfiles and adds new ones.  The removed
dockerfiles were originally used for building the testing images, but
now those images are generated by Docker Hub from the decred/dcrdocker
dockerfiles.

The new dockerfiles provide a way to build an image for running dcrd.
The main Dockerfile runs dcrd inside the same image used for building.
Dockerfile.alpine provides an alternative image that copies the built
files into an alpine based container, removing all build related content
and providing a securer and slimmer alternative.
This commit is contained in:
orthomind 2018-06-20 23:39:20 +10:00 committed by Dave Collins
parent 029fc17e9c
commit 6c9bc1d890
6 changed files with 84 additions and 107 deletions

View File

@ -1,2 +1,3 @@
*~
vendor
Dockerfile*

12
Dockerfile Normal file
View File

@ -0,0 +1,12 @@
FROM golang:1.10.3
WORKDIR /go/src/github.com/decred/dcrd
COPY . .
RUN go get -u github.com/golang/dep/cmd/dep
RUN dep ensure
RUN go install . ./cmd/...
EXPOSE 9108
CMD dcrd

View File

@ -1,52 +0,0 @@
#decred-golang-builder-1.10
# This image may be called with the run_tests.sh script included in any of the
# supported go repos.
# ./run_tests.sh 1.10
FROM golang:1.10
LABEL description="Decred golang builder image"
LABEL version="1.0"
LABEL maintainer "dhill@mindcry.org"
ENV TERM linux
ENV USER build
# create user
RUN adduser --disabled-password --gecos '' $USER
# update base distro & install build tooling
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install -qy rsync
# create directory for build artifacts, adjust user permissions
RUN mkdir /release && \
chown $USER /release
# create directory to get source from
RUN mkdir /src && \
chown $USER /src && \
mkdir -p /go/src/github.com/decred/dcrd && \
mkdir -p /go/src/github.com/decred/dcrwallet && \
chown -R $USER /go/src
# switch user
USER $USER
ENV HOME /home/$USER
# get deps
ENV DEP_TAG v0.4.1
ENV GOMETALINTER_TAG v2.0.5
WORKDIR /go/src
RUN go get -v github.com/alecthomas/gometalinter && \
cd /go/src/github.com/alecthomas/gometalinter && \
git checkout $GOMETALINTER_TAG && \
go install && \
gometalinter --install && \
go get -v github.com/golang/dep && \
cd /go/src/github.com/golang/dep && \
git checkout $DEP_TAG && \
go install -i

View File

@ -1,52 +0,0 @@
#decred-golang-builder-1.9
# This image may be called with the run_tests.sh script included in any of the
# supported go repos.
# ./run_tests.sh 1.9
FROM golang:1.9.4
LABEL description="Decred golang builder image"
LABEL version="1.0"
LABEL maintainer "dhill@mindcry.org"
ENV TERM linux
ENV USER build
# create user
RUN adduser --disabled-password --gecos '' $USER
# update base distro & install build tooling
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install -qy rsync
# create directory for build artifacts, adjust user permissions
RUN mkdir /release && \
chown $USER /release
# create directory to get source from
RUN mkdir /src && \
chown $USER /src && \
mkdir -p /go/src/github.com/decred/dcrd && \
mkdir -p /go/src/github.com/decred/dcrwallet && \
chown -R $USER /go/src
# switch user
USER $USER
ENV HOME /home/$USER
# get deps
ENV DEP_TAG v0.4.1
ENV GOMETALINTER_TAG v2.0.5
WORKDIR /go/src
RUN go get -v github.com/alecthomas/gometalinter && \
cd /go/src/github.com/alecthomas/gometalinter && \
git checkout $GOMETALINTER_TAG && \
go install && \
gometalinter --install && \
go get -v github.com/golang/dep && \
cd /go/src/github.com/golang/dep && \
git checkout $DEP_TAG && \
go install ./...

19
Dockerfile.alpine Normal file
View File

@ -0,0 +1,19 @@
# Build image
FROM golang:1.10.3
WORKDIR /go/src/github.com/decred/dcrd
COPY . .
RUN go get -u github.com/golang/dep/cmd/dep
RUN dep ensure
RUN CGO_ENABLED=0 GOOS=linux go install . ./cmd/...
# Production image
FROM alpine:3.6
RUN apk add --no-cache ca-certificates
COPY --from=0 /go/bin/* /bin/
EXPOSE 9108
CMD dcrd

View File

@ -13,8 +13,8 @@ dcrd maintains the entire past transactional ledger of Decred and allows
about Decred please see the
[project documentation](https://docs.decred.org/#overview).
Note: To send or receive funds and join Proof-of-Stake mining, you will also need
[dcrwallet](https://github.com/decred/dcrwallet).
Note: To send or receive funds and join Proof-of-Stake mining, you will also
need [dcrwallet](https://github.com/decred/dcrwallet).
This project is currently under active development and is in a Beta state. It
is extremely stable and has been in production use since February 2016.
@ -80,10 +80,59 @@ go install . ./cmd/...
```
For more information about Decred and how to set up your software please go to
our docs page at [docs.decred.org](https://docs.decred.org/getting-started/beginner-guide/).
our docs page at
[docs.decred.org](https://docs.decred.org/getting-started/beginner-guide/).
## Docker
### Running dcrd
You can run a decred node from inside a docker container. To build the image
yourself, use the following command:
```
docker build -t decred/dcrd .
```
Or you can create an alpine based image (requires Docker 17.05 or higher):
```
docker build -t decred/dcrd:alpine -f Dockerfile.alpine .
```
You can then run the image using:
```
docker run decred/dcrd
```
You may wish to use an external volume to customise your config and persist the
data in an external volume:
```
docker run --rm -v /home/user/dcrdata:/root/.dcrd/data decred/dcrd
```
For a minimal image, you can use the decred/dcrd:alpine tag. This is typically
a more secure option while also being a much smaller image.
You can run dcrctl from inside the image. For example, run an image (mounting
your data from externally) with:
```
docker run --rm -ti --name=dcrd-1 -v /home/user/.dcrd:/root/.dcrd \
decred/dcrd:alpine
```
And then run dcrctl commands against it. For example:
```
docker exec -ti dcrd-1 dcrctl getbestblock
```
### Running Tests
All tests and linters may be run in a docker container using the script
`run_tests.sh`. This script defaults to using the current supported version of
go. You can run it with the major version of Go you would like to use as the