duanfuxing2212 2018-08-04 10:16
浏览 183
已采纳

Docker撰写work_dir问题

I am trying to run a golang app using docker-compose, below is my compose configuration.

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"

On running the compose using command "docker-compose up" i get error "stat main.go: no such file or directory" even when main.go is available in working directory.

  • 写回答

1条回答 默认 最新

  • dpdhf02040 2018-08-04 12:28
    关注

    it works fine when your host dir layout is

    oxo@thor ~/Dropbox/Documents/code/docker/golang_working_dir $ find .
    .
    ./docker-compose.yaml
    ./simple-golang-app
    ./simple-golang-app/main.go
    

    so here we

    cd ~/Dropbox/Documents/code/docker/golang_working_dir
    docker-compose up
    

    for a more complex build involving dependancies I use a Dockerfile :

    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
    

    now update your docker-compose.yaml to use this new image :

    old

    image: golang:1.8-alpine
    

    new

    image: nirmal_golang_alpine:latest
    

    so your commands are

    docker build --tag nirmal_golang_alpine
    
    docker-compose up
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站