楽したい

常にWhat's upの精神

SQL50本ノックの環境構築をしようとしてサポートページからダウンロードしたシェルスクリプトを実行するとエラーになってしまう問題

SoftwareDesign2017年11月号の特集にあるSQL50本ノックをやろうとして公式サイトから環境構築のためのシェルスクリプトをダウンロードして、下記コマンドで実行しようとするとエラーになる。

実行コマンド

sh postgres_initialize.sh

エラー抜粋

Step 2/5 : RUN apt-get update &&   apt-get install -y wget unzip &&   wget https://ftp.postgresql.org/pub/projects/pgFoundry/dbsamples/pagila/pagila/pagila-0.10.1.zip -O /tmp/pagila-0.10.1.zip &&   unzip /tmp/pagila-0.10.1.zip -d /tmp &&   cat /tmp/pagila-0.10.1/pagila-schema.sql |   grep -v "CREATE PROCEDURAL LANGUAGE plpgsql" > /docker-entrypoint-initdb.d/pagila_init.sql &&   cat /tmp/pagila-0.10.1/pagila-data.sql >> /docker-entrypoint-initdb.d/pagila_init.sql
 ---> Running in 02819260eb91
Get:1 http://security.debian.org jessie/updates InRelease [44.9 kB]
Ign http://deb.debian.org jessie InRelease
Get:2 http://apt.postgresql.org jessie-pgdg InRelease [56.5 kB]
Get:3 http://deb.debian.org jessie-updates InRelease [7,340 B]
Get:4 http://deb.debian.org jessie Release.gpg [2,420 B]
Get:5 http://deb.debian.org jessie Release [148 kB]
Get:6 http://security.debian.org jessie/updates/main amd64 Packages [825 kB]
Get:7 http://deb.debian.org jessie/main amd64 Packages [9,098 kB]
Get:8 http://apt.postgresql.org jessie-pgdg/main amd64 Packages [204 kB]
Get:9 http://apt.postgresql.org jessie-pgdg/9.6 amd64 Packages [1,690 B]
Fetched 10.4 MB in 6s (1,594 kB/s)
W: Failed to fetch http://deb.debian.org/debian/dists/jessie-updates/InRelease  Unable to find expected entry 'main/binary-amd64/Packages' in Release file (Wrong sources.list entry or malformed file)

E: Some index files failed to download. They have been ignored, or old ones used instead.
The command '/bin/sh -c apt-get update &&   apt-get install -y wget unzip &&   wget https://ftp.postgresql.org/pub/projects/pgFoundry/dbsamples/pagila/pagila/pagila-0.10.1.zip -O /tmp/pagila-0.10.1.zip &&   unzip /tmp/pagila-0.10.1.zip -d /tmp &&   cat /tmp/pagila-0.10.1/pagila-schema.sql |   grep -v "CREATE PROCEDURAL LANGUAGE plpgsql" > /docker-entrypoint-initdb.d/pagila_init.sql &&   cat /tmp/pagila-0.10.1/pagila-data.sql >> /docker-entrypoint-initdb.d/pagila_init.sql' returned a non-zero code: 100

解決方法

ググったらそれっぽいのがあった。 https://superuser.com/questions/1423486/issue-with-fetching-http-deb-debian-org-debian-dists-jessie-updates-inrelease

上記を参考にして、公式サイトから落としてきたDockerfileにコマンドを追記してあげる。 追記する箇所は、Dockerfileの「FROM postgres:9.6.5」と「RUN apt-get update && \ ・・・」の間。

Dockerfile追記例

FROM postgres:9.6.5

# 追記するコマンドここから
RUN printf "deb http://archive.debian.org/debian/ jessie main\ndeb-src http://archive.debian.org/debian/ jessie main\ndeb http://security.debian.org jessie/updates main\ndeb-src http://security.debian.org jessie/updates main" > /etc/apt/sources.list
# ここまで

RUN apt-get update && \
  apt-get install -y wget unzip && \
  ・・・
  ・・・

追記したコマンドは、apt-getでパッケージを取得する際にダウンロード先を別の場所から取得するようにするためのコマンドらしい。 /etc/apt/sources.listがダウンロード先を指定できるファイルで、編集したらapt-get updateでアップデートをする必要があるので上記の位置にコマンドを追記したらうまいこと動いてくれるっていう感じ。

追記したらシェルスクリプトを実行してあげて、postgresにloginできたらOK。

参考 /etc/apt/sources.listについての説明 https://www.garunimo.com/program/linux/_etc_apt_sources_list.php