Even if I changed the code, the behavior of the application in the container did not change, which was a problem. This is a memo about how to deal with it. (It is not the system that the cache worked)
The ʻapp (executable file) built in the
Dockerfile was overwritten by the ʻapp
in the local directory of volumes set in docker-compose.yml
.
Therefore, I solved it by changing it so that it would not be mounted excessively.
Problem
Dockerfile
main.go
.docker-compose up -d --build
docker-compose build --no-cache
but the same ...Directory structure ↓
myapp
- docker-compose.yml
- Go
- Dockerfile
- main.go
- app
Partial code excerpt ↓
Dockerfile
FROM golang:1.12.12-alpine3.9 AS build
ENV GOPATH $GOPATH:/go
ENV PATH $PATH:$GOPATH/bin
ENV GO111MODULE=on
hogehoge
COPY . /go/src/app
WORKDIR /go/src/app
RUN go build -o app main.go
CMD ["./app"]
docker-compose.yml
version: '2'
services:
app:
build:
context: ./Go
dockerfile: Dockerfile
volumes:
- "./Go:/go/src/app"
container_name: go_app
ports:
- "127.0.0.1:8080:8080"
tty: true
restart: always
The cause was the local app I was trying to create.
The command execution order is RUN → volumes → CMD
, and the ʻapp built in the container was overwritten with the local ʻapp
.
In this case, only the session information had to be persisted and saved, so this one file was sufficient for sharing the file.
docker-compose.yml
volumes:
- "./Go/sessions:/go/src/app/sessions"
During development, it is more convenient to mount and edit the source code. Therefore, I thought it would be a good idea not to share only ʻapp`. (How to exclude some when mounting Volume with Docker)
In the first place, while I was making code changes for the purpose of persisting session information, something like this. (There is also a difference between the production server and the development server) Eventually, we will move to database management. (Of which)
Recommended Posts