【トラブル】【Docker】Docker に関するトラブル

■ はじめに

Docker によるトラブルシューティングを纏める。

なお、Windows / Docker Desktop でのトラブルシューティングに関しては
以下の関連記事を参照のこと。

Windows / Docker Desktop でのトラブル
https://dk521123.hatenablog.com/entry/2020/12/11/115814
Proxy環境下でdocker pullしたらエラー
https://dk521123.hatenablog.com/entry/2024/02/08/144941

目次

【1】docker 実行後、apt-get updateでエラー「Release file is not yet valid」表示
【2】コマンド「docker pull centos:latest」を実行後にエラー表示
【3】エラー「Got permission denied while trying to connect」が発生
【4】エラー「unable to remove repository reference "nginx"」が表示

【1】docker 実行後、apt-get updateでエラー「Release file is not yet valid」表示

以下のDocker ファイルで、
3行目「RUN apt-get update」を実行した際に
以下「エラー内容」が表示される

Dockerfile

FROM ubuntu:latest

RUN apt-get update
RUN apt-get install python3 python3-pip -y

RUN pip install --trusted-host pypi.python.org -r requirements.txt

RUN mkdir /app

エラー内容

・・・略・・・
Get:8 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Reading package lists...
E: Release file for http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease is not valid yet (invalid for another 22h 27min 59s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease is not valid yet (invalid for another 22h 28min 11s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease is not valid yet (invalid for another 22h 28min 33s). Updates for this repository will not be applied.
ERROR: Service 'app' failed to build : The command '/bin/sh -c apt-get update' returned a non-zero code: 100

 原因

* Docker デーモンが動いているホストの時刻がずれているため

 解決策

* 以下のように修正

Dockerfile(修正版)

FROM ubuntu:latest

RUN apt-get -o Acquire::Check-Valid-Until=false -o Acquire::Check-Date=false update && apt-get install python3 python3-pip -y

WORKDIR /code
ADD requirements.txt /code
RUN pip3 install -r requirements.txt

RUN mkdir /app

 参考文献

https://www.hamayanhamayan.com/entry/2020/03/14/113729

 【2】コマンド「docker pull centos:latest」を実行後にエラー表示

 エラー内容

docker: Error response from daemon: 
Get https://registry-1.docker.io/v2/: net/http:
request canceled while waiting for connection 
(Client.Timeout exceeded while awaiting headers).

 解決策

 * Dockerアイコンを右クリックし、[Settings]-[Network]で
   DNS Server での設定のAutomaticを止めて、Fixedの8.8.8.8に切り替える

 参考文献

http://satoyashiki.hatenablog.com/entry/2017/04/01/1756

【3】エラー「Got permission denied while trying to connect」が発生

エラー内容

docker compose up -d

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json?all=1&filters=%7B%22label%22%3A%7B%22com.docker.compose.project%3Dairflow%22%3Atrue%7D%7D&limit=0": dial unix /var/run/docker.sock: connect: permission denied

解決案

sudo chmod 666 /var/run/docker.sock

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# が表示されたらOK

参考文献

https://qiita.com/Nw3965/items/8e75da0012cb7a451cc2

【4】エラー「unable to remove repository reference "nginx"」が表示

Docker Image削除時に、
エラー「unable to remove repository reference "nginx"」が表示する

エラーメッセージ

$ docker rmi nginx
Error response from daemon: conflict:
 unable to remove repository reference "nginx" (must force)
 - container xxxxxxxxxx is using its referenced image yyyyyyyyyyyyyy

原因

https://qiita.com/gisuyama7/items/82086b30f6b8e6fc14cf

より抜粋
~~~~~~~~~~~~~~
イメージを削除するには、コンテナが停止している必要があるため。
コンテナは稼働が止まっている状態でも、コンテナとしては存在は残っている。
よって、コンテナを削除してからでなければイメージは削除できない。
~~~~~~~~~~~~~~

解決案

# Docker 全Imageのプロセス表示
docker ps -a
# docker image ls -a

# コンテナの削除
docker rm <CONTAINER ID>
# docker container rm <CONTAINER ID>

# イメージ削除
docker rmi nginx
# docker image rm nginx

 関連記事

Docker ~ 基礎知識編 ~
https://dk521123.hatenablog.com/entry/2020/04/24/160044
 Docker ~ Windows / 環境構築編 ~
https://dk521123.hatenablog.com/entry/2017/09/23/235818
 Docker ~ 基本編 / docker-compose.yml ~
https://dk521123.hatenablog.com/entry/2020/12/18/152949
Windows / Docker Desktop でのトラブルシューティング
https://dk521123.hatenablog.com/entry/2020/12/11/115814
Proxy環境下でdocker pullしたらエラー
https://dk521123.hatenablog.com/entry/2024/02/08/144941
Docker ~ トラブルシュート方法 ~
https://dk521123.hatenablog.com/entry/2023/12/12/034018
サービス管理 ~ service/systemctl ~
https://dk521123.hatenablog.com/entry/2016/07/26/223003