I was in trouble because the behavior of docker container did not change

Introduction

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)

Remedy first

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

  1. I have a golang app that I was creating in a docker container
  2. I try to buy and start the app in Dockerfile
  3. For example, edit and save main.go.
  4. Recreate and launch the app with docker-compose up -d --build
  5. That? It hasn't changed! ?? (Build is running)
  6. Try 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

Cause

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.

approach

Don't mount extra files

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"

Exclude files that should not be shared

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 conclusion

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

I was in trouble because the behavior of docker container did not change
I was in trouble because the character string in the PDF was strange
The story of debugging in the local environment because the compilation did not work with Read the Docs
The result of analyzing Kant's "criticism of judgment" that I did not read at all was interesting
I checked the contents of docker volume
Check the behavior of destructor in Python
In Python, change the behavior of the method depending on how it is called
Change the font size of the legend in df.plot
Behavior when Trainable = False of Container in Keras
Enter into stdin of the running Docker container
About the behavior of Model.get_or_create () of peewee in Python
Put Python3 in Docker container of Amazon Linux2
I will summarize what I was happy to do to get out of the state where I do not know the letter D of Docker
About the matter that the contents of Python print are not visible in docker logs
Here is one of the apps with "artificial intelligence" that I was interested in.
What I did when I was angry to put it in with the enable-shared option
Code memo that I was having trouble with not being on the discord.py site
[Probability] I will explain because the robot problem of Center 2020 Mathematics 1 ・ A was interesting.
Change the time zone with Docker in Oracle Database
The performance of PHP was better than I expected
Not being aware of the contents of the data in python
The story that yapf did not work in vscode
Ventilation is important. What I did to keep track of the C02 concentration in the room
What to do if the image is not displayed using matplotlib etc. in the Docker container
I was in charge of maintaining the Fabric script, but I don't know.> <To those who
The story of when I was addicted to Caused by SSLError ("Can't connect to HTTPS URL because the SSL module is not available.")
A note on the default behavior of collate_fn in PyTorch
I tried the accuracy of three Stirling's approximations in python
I wrote the basic operation of Seaborn in Jupyter Lab
The story that `while queue` did not work in python
Change the log retention period of CloudWatch Logs in Lambda
Check when the Docker container does not connect to the Internet
I tried a little bit of the behavior of the zip function
I wrote the basic operation of Numpy in Jupyter Lab.
[Python] Tensorflow 2.0 did not support Python 3.8, so the story of downgrading Python
The story of exclude / include that Serverless Framework beginners misunderstood (did not understand) in beginner Pythonista