源文件已更新,但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.

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