LoginSignup
1
1

More than 3 years have passed since last update.

CentOS8でdocker buildのdnf installが失敗する

Last updated at Posted at 2019-11-26

CentOS8でdocker buildのdnf installが失敗する

社内VPNでNginxを立てようとしたときの話。
CentOS8とDockerをインストールし、docker buildを行ったところdnf installが上手くいかずハマったのでメモ。

環境

  • CentOS Linux release 8.0.1905 (Core)
  • Docker version 18.06.3-ce, build d7080c1

  • SELinux

# getenforce
Enforcing
  • Firewalld
# firewall-cmd --list-all
public (active)
target: ACCEPT
icmp-block-inversion: no
interfaces: enp1s0
sources: 192.168.0.0/16
services: cockpit dhcpv6-client http https ssh
ports: 8000/tcp
protocols: 
masquerade: no
forward-ports: 
source-ports: 
icmp-blocks: 
rich rules:

Dockerのサービス変更

# vi /usr/lib/systemd/system/docker.service

Dockerサービスにて生成されるファイルパスの変更とDNS指定を行いました

Environment="DOCKER_OPTS=-g /mnt/HDD/docker/system --dns=8.8.8.8"
ExecStart=/usr/bin/dockerd $DOCKER_OPTS

Dockerサービスを再起動

# systemctl daemon-reload
# systemctl restart docker

Dockerfile

# cat Dockerfile
FROM centos:8 
MAINTAINER name <email>

EXPOSE 80

RUN dnf install -y nginx 
CMD ["nginx", "-g", "daemon off;"]

ビルドしてみた

# docker build -t nginx -f Dockerfile .

dnf installで失敗する。
AppStreamやBase、Extrasに0MBと表示され、dnf install nginxが失敗しました

対策

Dockerfileにpingを書いてみたところ、IPアドレス指定であれば反応があるが、URL指定だと失敗しました。
よって、DNSによる名前解決ができず、dnf installが失敗しているようです。
docker buildで下記のようにホストのネットワークを指定したところ問題なくビルドできました。

# docker build -t nginx -f Dockerfile --network host .

さいごに

役に立ちましたら、いいねのクリックをお願いします。

1
1
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
1
1