[GO] The case that "apt-get update" defined in "Dockerfile" could not be done at the time of "docker-compose build"

1. Purpose of this article

In order to build a golang development environment with docker, dockerfile was set as follows. However, as shown in [2. Error details](# 2. Error details), it could not be built. .. .. I will leave it as a memorandum!

dockerfile


#reference
FROM golang:latest

ENV GO111MODULE=on
ENV GOLANG_VERSION=1.15.3

WORKDIR /go/src/backend

#This apt-get doesn't work ...
RUN apt-get update -y && apt-get install -y vim

COPY /backend/go.mod /backend/go.sum /go/src/backend/

2. Error details

docker-compose build doesn't work.

[root@localhost vagrant]# docker-compose build
nginx uses an image, skipping
Building vue
Step 1/2 : FROM node:10
 ---> 56387899b840
Step 2/2 : RUN apt-get update &&     apt-get install git &&     npm install -g npm &&     npm install -g @vue/cli
 ---> Using cache
 ---> 2f3aa344d453

Successfully built 2f3aa344d453
Successfully tagged vagrant_vue:latest
Building go
Step 1/7 : FROM golang:latest
 ---> 4a581cd6feb1
Step 2/7 : ENV GO111MODULE=on
 ---> Using cache
 ---> dfe811dc936e
Step 3/7 : ENV GOLANG_VERSION=1.15.3
 ---> Using cache
 ---> dc7206ac34f4
Step 4/7 : ENV GOPATH=/go
 ---> Using cache
 ---> 73183c5707e4
Step 5/7 : WORKDIR /go/src/backend
 ---> Using cache
 ---> a3cb200b2052
Step 6/7 : RUN apt-get update -y && apt-get install -y vim
 ---> Running in a57f9a0f8c5f
Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:2 http://deb.debian.org/debian buster InRelease [121 kB]
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:4 http://deb.debian.org/debian buster/main amd64 Packages [7906 kB]
Reading package lists...
E: Release file for http://security.debian.org/debian-security/dists/buster/updates/InRelease is not valid yet (invalid for another 1d 8h 21min 59s). Updates for this repository will not be applied.
E: Release file for http://deb.debian.org/debian/dists/buster-updates/InRelease is not valid yet (invalid for another 2d 0h 11min 1s). Updates for this repository will not be applied.
ERROR: Service 'go' failed to build : The command '/bin/sh -c apt-get update -y && apt-get install -y vim' returned a non-zero code: 100

Looking here, the time setting seems to be bad. .. ..

E: Release file for http://security.debian.org/debian-security/dists/buster/updates/InRelease is not valid yet (invalid for another 1d 8h 21min 59s). Updates for this repository will not be applied.
E: Release file for http://deb.debian.org/debian/dists/buster-updates/InRelease is not valid yet (invalid for another 2d 0h 11min 1s). Updates for this repository will not be applied.

3. Solution

Is the time of the host OS (CentOS7 in this case) wrong ??

$date
Thu Oct 22 17:49:15 JST 2020

The work date and time was around 22:00 on October 24th, so there is no doubt that it is off. .. .. Try changing the host OS to the current time by referring to the following site. ** Reference article name: Set the Linux server time (with the current time) ** ** Reference URL: https://qiita.com/ntkgcj/items/0ef1c02665b3d9a3971d **

$ docker-compose build
Building go
Step 1/7 : FROM golang:latest
 ---> 4a581cd6feb1
Step 2/7 : ENV GO111MODULE=on
 ---> Using cache
 ---> dfe811dc936e
Step 3/7 : ENV GOLANG_VERSION=1.15.3
 ---> Using cache
 ---> dc7206ac34f4
Step 4/7 : ENV GOPATH=/go
 ---> Using cache
 ---> 73183c5707e4
Step 5/7 : WORKDIR /go/src/backend
 ---> Using cache
 ---> a3cb200b2052
Step 6/7 : RUN apt-get update -y && apt-get install -y vim
 ---> Running in e5e484eea0df
Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:2 http://deb.debian.org/debian buster InRelease [121 kB]
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:4 http://security.debian.org/debian-security buster/updates/main amd64 Packages [243 kB]
Get:5 http://deb.debian.org/debian buster/main amd64 Packages [7906 kB]
Get:6 http://deb.debian.org/debian buster-updates/main amd64 Packages [7868 B]
···abridgement
Successfully tagged vagrant_go:latest

** Build successful! !! ** **

Recommended Posts

The case that "apt-get update" defined in "Dockerfile" could not be done at the time of "docker-compose build"
The case that @Autowired could not be used in JUnit5
About the case that ("b" .. "aa") could not be used in Ruby Range
The story that the forced update could not be implemented
Solved the problem that apt-get update could not be executed on Ubuntu (Virtual Box) on Windows.
The repository ... is not signed error in docker build apt-get update
The story of stopping because the rails test could not be done
What you are doing in the confirmation at the time of gem update
Correspond to "error that basic authentication does not pass" in the test code "The story that could not be done"
Summary of problems that I could not log in to firebase
Note that Insert could not be done with Spring Data JDBC
About the matter that tends to be confused with ARG of Dockerfile which is a multi-stage build