Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Commit

Permalink
源码方式docker镜像尺寸过大,改为build文件
Browse files Browse the repository at this point in the history
  • Loading branch information
hb-chen committed Oct 29, 2017
1 parent 2bea323 commit 0da5c71
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ vendor

# Bindata
# assets/assets.go
# template/template.go
# template/template.go
/echo-web
36 changes: 31 additions & 5 deletions Docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,42 @@

### 创建镜像
```
$ docker build -t echo-web .
$ docker build -t hbchen/echo-web:v0.0.1 .
```

### 运行容器
```
$ docker run \
-p 8080:8080 \
--name=echo-web \
echo-web
-p 8080:8080 \
--name=echo-web \
hbchen/echo-web:v0.0.1
```

### MySQL、Redis、Memcached等服务配置问题
- 如果是服务在宿主机需要配置服务IP为主机IP,127.0.0.1/localhost网络不通
```bash
如果是服务在宿主机需要配置服务IP为主机IP,127.0.0.1/localhost网络不通

# hbchen/echo-web使用的配置,在宿主机host上做个映射(192.168.1.8为主机IP)
# 192.168.1.8 mysql.localhost.com
# 192.168.1.8 redis.localhost.com
# 192.168.1.8 memcached.localhost.com
[database]
host = "mysql.localhost.com"

[redis]
server = "redis.localhost.com:6379"

[memcached]
server = "memcached.localhost.com:11211"
```

### 自动修改/etc/hosts,映射自定义域名到主机IP
```bash
$ vi ~/.profile

# 添加
grep -v "etcd.localhost.com\|consul.localhost.com\|mysql.localhost.com\|redis.localhost.com\|memcached.localhost.com" /etc/hosts > ~/hosts_temp
cat ~/hosts_temp > /etc/hosts
LC_ALL=C ifconfig en0 | grep 'inet ' | cut -d ' ' -f2 | awk '{print $1 " etcd.localhost.com\n" $1 " consul.localhost.com\n" $1 " mysql.localhost.com\n"$1 " redis.localhost.com\n" $1 " memcached.localhost.com"}' >> /etc/hosts
```

34 changes: 24 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
FROM golang:1.8.3
FROM alpine:3.2

WORKDIR /go/src/echo-web
COPY . .
# 配置文件
ADD conf /conf
ADD echo-web /echo-web

#RUN go-wrapper download # "go get -d -v ./..."
#RUN go-wrapper install # "go install -v ./..."

# Bindata工具安装
RUN go get -u github.com/jteeuwen/go-bindata/...
WORKDIR /

# conf.toml配置端口一致
EXPOSE 8080

# CMD ["go-wrapper", "run"] # ["app"]
CMD ./run.sh -a -t
ENTRYPOINT [ "/echo-web" ]

# 源码方式
# FROM golang:1.8.3
#
# WORKDIR /go/src/echo-web
# COPY . .
#
# #RUN go-wrapper download # "go get -d -v ./..."
# #RUN go-wrapper install # "go install -v ./..."
#
# # Bindata工具安装
# RUN go get -u github.com/jteeuwen/go-bindata/...
#
# # conf.toml配置端口一致
# EXPOSE 8080
#
# # CMD ["go-wrapper", "run"] # ["app"]
# CMD ./run.sh -a -t
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ case $OS in
linux)
# Linux
echo "$LogPrefix `date +"%H:%M:%S"` build linux bin"
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go install
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags '-w' -o echo-web ./echo.go
;;
*)
# 本机
echo "$LogPrefix `date +"%H:%M:%S"` build local bin"
go install
go build -a -installsuffix cgo -ldflags '-w' -o echo-web ./echo.go
;;
esac

Expand Down

0 comments on commit 0da5c71

Please sign in to comment.