douzhi3105 2018-08-23 09:19
浏览 57

源文件已更新,但CMD不能反映

I'm new to docker and am trying to dockerize an app I have. Here is the dockerfile I am using:

FROM golang:1.10

WORKDIR /go/src/github.com/myuser/pkg
ADD . .

RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
RUN dep ensure

CMD ["go", "run", "cmd/pkg/main.go"]

The issue I am running into is that I will update source files on my local machine with some log statements, rebuild the image, and try running it in a container. However, the CMD (go run cmd/pkg/main.go) will not reflect the changes I made.

I looked into the container filesystem and I see that the source files are updated and match what I have locally. But when I run go run cmd/pkg/main.go within the container, I don't see the log statements I added.

I've tried using the --no-cache option when building the image, but that doesn't seem to help. Is this a problem with the golang image, or my dockerfile setup?

UPDATE: I have found the issue. The issue is related to using dep for vendoring. The vendor folder had outdated files for my package because dep ensure was pulling them from github instead of locally. I will be moving to go 1.1 which support to go modules to fix this.

  • 写回答

1条回答 默认 最新

  • doushajian2018 2018-08-23 11:13
    关注

    I see several things:

    According to your Dockerfile

    1. Maybe you need a dep init before dep ensure
    2. Probably you need to check if main.go path is correct.

    According to docker philosophy

    1. In my humble opinion, you should create an image with docker build -t <your_image_name> ., executing that where your Dockerfile is, but without CMD line.
    2. I would execute your go run <your main.go> in your docker run -d <your_image_name> go run <cmd/pkg/main.go> or whatever is your command.

    If something is wrong, you can check exited containers with docker ps -a and furthermore check logs with docker logs <your_CONTAINER_name/id>

    Other way to check logs is access to the container using bash and execute go run manually:

    docker run -ti <your_image_name> bash
    # go run blablabla
    
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统