我正在尝试使用docker-compose运行golang应用,以下是我的撰写配置。
version: '2'
services:
#Application container
go:
image: golang:1.8-alpine
ports:
- "80:8080"
links:
- mongodb
environment:
DEBUG: 'true'
PORT: '8080'
working_dir: /go/src/simple-golang-app
command: go run main.go
volumes:
- ./simple-golang-app:/go/src/simple-golang-app
mongodb:
image: mvertes/alpine-mongo:3.2.3
restart: unless-stopped
ports:
- "27017:27017"
使用命令“ docker-compose up”运行撰写文件时,出现错误“ stat main.go:没有这样的文件或目录”,即使main.go在工作目录中也可用。
答案 0 :(得分:0)
当您的主机目录布局为
时,它可以正常工作<FontAwesomeIcon icon="users" />
所以我们在这里
oxo@thor ~/Dropbox/Documents/code/docker/golang_working_dir $ find .
.
./docker-compose.yaml
./simple-golang-app
./simple-golang-app/main.go
对于涉及依赖关系的更复杂的构建,我使用Dockerfile:
cd ~/Dropbox/Documents/code/docker/golang_working_dir
docker-compose up
现在更新您的docker-compose.yaml以使用此新图像:
旧
FROM golang:1.8-alpine
RUN mkdir -p /go/src/simple-golang-app/
COPY simple-golang-app/main.go /go/src/simple-golang-app
WORKDIR /go/src/simple-golang-app
RUN apk add --no-cache git mercurial && go get -v -t ./... && apk del git mercurial
RUN go install ./...
RUN go build
ENV PORT 9000
新
image: golang:1.8-alpine
所以您的命令是
image: nirmal_golang_alpine:latest