LoginSignup
0
0

はじめに

お約束
この記事は私が所属する企業には一切関係しません。
ご了承ください。

実行環境は下記のとおりです。

$ cat /etc/os-release 
NAME="CentOS Linux"
VERSION="8"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"

事の発端

普段より Docker を使って開発をしています。
つい先日もnginxを使って開発をしていたのですが、apt update でエラーが発生しました。

Release file for http://security.debian.org/debian-security/dists/buster/updates/InRelease is not valid yet (invalid for another 9min 35s). Updates for this repository will not be applied.

調べてみると時刻がズレていることが分かったのだが、その後色々と躓いたので備忘録

TL;DR.

ホストOSの時刻がズレていた…

> date
2024年  6月 27日 木曜日 11:05:26 JST # 20 分程度ズレている

まず スーパーユーザーになって

sudo su

chrony を使って、ホストの時刻を合わせる1

> yum -y install chrony
> systemctl start chronyd
> chronyc makestep
200 OK

確認!

> date
2024年  6月 27日 木曜日 11:25:26 JST # 直った!
Docker component
compose.yaml
services:
  cotomi_fastapi:
    build: ./fastapi
    container_name: cotomi_fastapi_${USER_NAME}
    command: bash -c "uvicorn main:app --host 0.0.0.0"
    ports:
      - ${FASTAPI_PORT}:8000
    volumes:
      - ./fastapi:/app
    env_file: .env
    networks:
      - default

  cotomi_nginx:
    build: ./nginx
    container_name: cotomi_nginx_${USER_NAME}
    extends:
      file: common.yaml
      service: common_service
    volumes:
      - ./nginx/conf/nginx/default.conf:/etc/nginx/conf.d/default.conf
      - ./nginx/conf/nginx/nginx.service:/lib/systemd/system/nginx.service
      - ./nginx//ssl:/etc/nginx/ssl
    ports:
      - 443:443
      - 80:80
    networks:
      - default
    depends_on:
      - cotomi_fastapi


networks:
  default:
    name: ${NET_NAME}
    external: true
FROM nginx:latest

# 環境変数の設定
ENV TZ=Asia/Tokyo

# 必要なパッケージのインストール
RUN apt update && \
    apt install -y \
    curl \
    wget \
    libpcre3 \
    libpcre3-dev \
    libssl-dev \
    perl \
    make \
    build-essential \
    ca-certificates \
    libreadline-dev \
    libncurses5-dev \
    libncursesw5-dev \
    zlib1g-dev

# LuaJITのインストール
RUN wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz && \
    tar zxvf LuaJIT-2.0.5.tar.gz && \
    cd LuaJIT-2.0.5 && \
    make && make install && \
    cd .. && rm -rf LuaJIT-2.0.5*

# OpenRestyのインストール
RUN wget https://openresty.org/download/openresty-1.19.9.1.tar.gz && \
    tar zxvf openresty-1.19.9.1.tar.gz && \
    cd openresty-1.19.9.1 && \
    # sh -c './configure' && \
    # make && make install && \
    # cd .. && rm -rf openresty-1.19.9.1*
    cd bundle && \
    tar zxvf ngx_lua-0.10.20.tar.gz && \
    mv ngx_lua-0.10.20 /tmp/ngx_http_lua_module

# Nginxのソースコードを取得
RUN wget http://nginx.org/download/nginx-1.19.9.tar.gz && \
    tar zxvf nginx-1.19.9.tar.gz && \
    cd nginx-1.19.9 && \
    ./configure --prefix=/etc/nginx \
    --sbin-path=/usr/sbin/nginx \
    --conf-path=/etc/nginx/nginx.conf \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log \
    --pid-path=/var/run/nginx.pid \
    --lock-path=/var/run/nginx.lock \
    --with-http_ssl_module \
    --with-pcre \
    --with-stream \
    --with-http_v2_module \
    --add-module=/tmp/ngx_http_lua_module && \
    make && make install && \
    cd .. && rm -rf nginx-1.19.9*

CMD ["nginx", "-g", "daemon off;"]

試したこと

コンテナ内の時刻を合わせる

Dockerfile
RUN ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

そもそもホストの時刻がズレているので関係ありませんでした…

ホストマシンのリブート

sudo reboot

リブートしてもタイムゾーン変わんねぇよ!!!

ntpdate での修正2

> sudo ntpdate ntp.nict.jp
bash: ntpdate: コマンドが見つかりませんでした...
> sudo yum install ntp
エラー: 表示するための一致したパッケージはありません

ntp って無いんですね…っていうのを知りました

  1. https://qiita.com/thzking/items/c2bcf7d60963b4dab7b6

  2. https://zenn.dev/karaage0703/articles/47838858dd3107#ntpdate

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0