質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

解決済

3回答

6554閲覧

dokcer build(bridge mode)がerrorになってしまいます

tetuya0703

総合スコア7

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

0クリップ

投稿2018/05/24 04:29

Dockerのhost環境をbridge modeに設定変更をしました
変更方法は下記の通りです

1. ip addr del 192.168.215.181/24 dev ens33 2. docker network create \ --driver bridge \ --subnet=192.168.215.0/24 \ --gateway=192.168.0.181 \ --opt "com.docker.network.bridge.name"="br0" \ shared_nw 3. brctl addif br0 ens3

上記の通り、br0を作成し、docker hostからinternetへのアクセスを及び、他のホストからdocker hostへのsshが出来ることを確認し、以下のDockerfileをbuildしようとしたのですが、errorになってbuildできません

Dockerfile

1FROM centos:7 2MAINTAINER Admin 3 4RUN yum -y install initscripts MAKEDEV 5RUN yum check 6RUN yum -y update 7RUN yum -y install net-tools 8 9# ansible install 10RUN yum -y install wget 11RUN wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm && rpm -ivh epel-release-latest-7.noarch.rpm 12 13RUN yum -y install ansible 14 15# ssh install 16RUN yum -y install openssh-server 17RUN sed -ri 's/^#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config 18RUN ssh-keygen -t rsa -N "" -f /etc/ssh/ssh_host_rsa_key 19 20RUN echo 'root:password' | chpasswd 21 22EXPOSE 22 23 24CMD ["/usr/sbin/sshd", "-D"]

build error

docker build -t ansible-docker:1.1 . Sending build context to Docker daemon 2.56kB Step 1/17 : FROM centos:7 ---> e934aafc2206 Step 2/17 : MAINTAINER Admin <testuya.saito@ntt.com> ---> Using cache ---> 6b33ecb34d48 Step 3/17 : RUN echo 'nameserver 8.8.8.8' >> /etc/resolv.conf ---> Using cache ---> 9075f4007389 Step 4/17 : RUN yum -y install initscripts MAKEDEV ---> Running in 7f64a271a571 Loaded plugins: fastestmirror, ovl One of the configured repositories failed (Unknown), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this: 1. Contact the upstream for the repository and get them to fix the problem. 2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work). 3. Run the command with the repository temporarily disabled yum --disablerepo=<repoid> ... 4. Disable the repository permanently, so yum won't use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage: yum-config-manager --disable <repoid> or subscription-manager repos --disable=<repoid> 5. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true Cannot find a valid baseurl for repo: base/7/x86_64 Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error" The command '/bin/sh -c yum -y install initscripts MAKEDEV' returned a non-zero code: 1

上記のerrorの内容から、containerからyumに関するRepositoryの名前解決が出来ないのかと考え、下記の方法を試してみました

対策
/usr/lib/systemd/system/docker.serviceの
ExecStart=/usr/bin/dockerd -D --dns=8.8.8.8

結果としては、上記と同じerrorになり、Docker buildが出来ませんでした

このような状況なのですが、Docker hostのネットワーク環境をbrige modeした場合、どのように対応すれば、docker buildができるのでしょうか

識者の皆様、ご指導よろしくお願いします

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答3

0

ベストアンサー

ブリッジにしているので、docker コンテナには 192.168.215.0/24 サブネット内にある DHCPサーバーから、IPアドレス、デフォルトゲートウェイ、ネームサーバーが割り当てられるのですよね? docker ホストからではなく。

まず、docker run で /bin/bash でも起動してみて、IPアドレスなどが割り当てられているか、yum リポジトリサーバーに接続できるか確認してみてはいかがでしょうか。

###(2018/05/28 18:02) 追記
思い違いをしていたかもしれません。
作成した br0 ネットワークでも、docker ホストが IPアドレスを割り当ててくれませんでしょうか?

試しに、docker run -it --network=br0 --name test_br0 centos:7 /bin/bash で起動し、docker ホストから docker inspect test_br0 で IPAddress, Gateway が割り当てられているか、yum を実行できるか確認ください。

"docker network create" 時の "--gateway=192.168.0.181" は 192.168.215.181 の Typo ですよね?

確認できたら、docker build --network=br0 (略) で br0 を指定してビルドを実行してみてください。

###(2018/05/31 11:47) 追記

上記を確認する限り、IPAddressとGatewayは割り振られているのですが
IPAddressは本来のshares_nwのgatewayのIPAddressであり、DHCPでは割り振られないIPAddressが割り振られている状況です

これは正しい動作です。
Docker ホストがサブネット 192.168.215.0/24 の中から IPアドレスを割り当てます。
コンテナのデフォルトゲートウェイは "--gateway=" で指定した 192.168.215.181 (Docker ホストの br0 の IPアドレス)になります。
Docker ホストの iptables で Forward, NAT して、外部と通信できるようになっているはず。

念のため、containerにログインをして
yum -y install net-tools
を実行しましたが、以下の通りのerrorでnet-toolsのinstallができませんでした

Docker ホストから割り当てられた 192.168.215.1 が既存のホストと競合しているのかもしれません。
192.168.215.0/24 の中で使用していない IPアドレスを(例えば 192.168.215.251)コンテナの固定IPアドレスとして用意して、docker run -it --network=shared_nw --ip 192.168.215.251 --name (任意) centos:7 /bin/bash とすると、外部と通信できませんでしょうか?

containerにはvethが割り振られ、ens33とbridgeをしていますが、うまくDHCPサーバーからIPを取得できていないようです

192.168.215.0/24 内の DHCPサーバーから IPアドレスを割り当ててもらうには、コンテナ内で dhclient を実行する必要があります。
簡単ではなさそうです。
docker run に "--privileged" オプションも必要になると思います。

https://www.agilegroup.co.jp/technote/docker-network-in-bridge.html

pipework というものを使う方法もあるようです。

http://www.itmedia.co.jp/enterprise/articles/1703/31/news031.html

投稿2018/05/24 14:10

編集2018/05/31 02:47
TaichiYanagiya

総合スコア12146

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

tetuya0703

2018/05/31 00:12

ご指導ありがとうございます 再度、以下のコマンドのbr0を作成しました docker network create \ --driver bridge \ --subnet=192.168.215.0/24 \ --gateway=192.168.0.181 \ --opt "com.docker.network.bridge.name"="br0" \ shared_nw 上記でbr0を作成したあとに brctl addif br0 ens33 を実行し、ens33をbr0をブリッジしました その後、ご指導頂いたとおり docker run -it --network=shard_nw --name test_br0_1 centos:7 /bin/bash を実行し、その後 docker inspect test_br0_1 でnetworkの状況を確認したところ、以下の通りでした "NetworkSettings": { "Bridge": "", "SandboxID": "3f7c87601d946a4be210251d3a06db302cd9c208c62217295df15e6a31de4680", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": {}, "SandboxKey": "/var/run/docker/netns/3f7c87601d94", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "", "Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "MacAddress": "", "Networks": { "shared_nw": { "IPAMConfig": null, "Links": null, "Aliases": [ "8cab522a83a8" ], "NetworkID": "f58eca5dc4be6019cb09b545591daa6c3357c8645a94a5f2c6940790f1e73533", "EndpointID": "64b7d6662b91abf9a0b42534c94d6a1c62cd96ec456cf9302af63a6b2d439711", "Gateway": "192.168.215.181", "IPAddress": "192.168.215.1", "IPPrefixLen": 24, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:c0:a8:d7:01" } } } 上記を確認する限り、IPAddressとGatewayは割り振られているのですが IPAddressは本来のshares_nwのgatewayのIPAddressであり、DHCPでは割り振られないIPAddressが割り振られている状況です 念のため、containerにログインをして yum -y install net-tools を実行しましたが、以下の通りのerrorでnet-toolsのinstallができませんでした Loaded plugins: fastestmirror, ovl Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was 14: curl#7 - "Failed connect to mirrorlist.centos.org:80; Operation now in progress" One of the configured repositories failed (Unknown), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this: 1. Contact the upstream for the repository and get them to fix the problem. 2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work). 3. Run the command with the repository temporarily disabled yum --disablerepo=<repoid> ... 4. Disable the repository permanently, so yum won't use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage: yum-config-manager --disable <repoid> or subscription-manager repos --disable=<repoid> 5. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true Cannot find a valid baseurl for repo: base/7/x86_64 また、containerを起動時のbrctl showの結果は以下の通りです br0 8000.024230039371 no ens33 veth3394207 docker0 8000.024247366831 no containerにはvethが割り振られ、ens33とbridgeをしていますが、うまくDHCPサーバーからIPを取得できていないようです お忙しい中、恐縮ですが、解決策のご教授をいただけますと幸いです どうぞよろしくお願い申し上げます
guest

0

TaichiYanagiyaさん

ご指導ありがとうございます
ご認識の通り、dockerのcontainerにstatic-ipを付与すると、外部との通信が問題なく実施することができました
たぶん、dhcpでcontainerにIPAddressを付与するのはdhcp-clientが必要になると思います
一番簡易な方法としては、dockerをbuildするサーバーとdcoker containerを動作するサーバーを分けてしまい
dockerをbuildしたあとに、docker hub等にpushしてdcoker containerを動作させるサーバーでpullさせることが一番簡単かなと考えております

いろいろとご教示いただきありがとうございました
今後ともよろしくおねがいします

投稿2018/05/31 06:02

tetuya0703

総合スコア7

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

TaichiYanagiyaさん

ご指導ありがとうございます
TaichiYanagiyaさんがご指摘をされている通り、私も同様の問題を考えました

docker buildで失敗をしたイメージを、以下のようにコンテナ化をして内容を確認してみました

1. docker commit "container-id" builddebug 2. docker run --rm -it builddebug /bin/bash

上記の通り、docker buildが失敗をしたものを一時期的にイメージかしてcontainerにログインをして状況を確認してみました。所がdefaultのcentos:7のイメージではifconfig及びipコマンド等が実行をすることができないので、実際にbuilddebugのイメージにIP Addressが付与されているか確認をすることが出来ませんでした

他にbuilddebugのイメージの状態を確認をする方法として、docker inspectを利用してbuilddebugの状況を確認すると、以下のような状況でした

[ { "Id": "sha256:53230d24aa6a9668943c044d6c588e05d2a179289798704c03b9c00661458e3e", "RepoTags": [ "builddebug:latest" ], "RepoDigests": [], "Parent": "sha256:9075f4007389767910cbacdad9510111a45b802e40b9d3784bf78afd97510d3b", "Comment": "", "Created": "2018-05-24T08:25:37.096187964Z", "Container": "93f32dd6501f8488e9a55e71383b4c6180f70442a454493351aef1ab1929cc39", "ContainerConfig": { "Hostname": "93f32dd6501f", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "/bin/sh", "-c", "yum -y install initscripts MAKEDEV" ], "ArgsEscaped": true, "Image": "sha256:9075f4007389767910cbacdad9510111a45b802e40b9d3784bf78afd97510d3b", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "org.label-schema.schema-version": "= 1.0 org.label-schema.name=CentOS Base Image org.label-schema.vendor=CentOS org.label-schema.license=GPLv2 org.label-schema.build-date=20180402" } }, "DockerVersion": "18.03.1-ce", "Author": "", "Config": { "Hostname": "93f32dd6501f", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "/bin/sh", "-c", "yum -y install initscripts MAKEDEV" ], "ArgsEscaped": true, "Image": "sha256:9075f4007389767910cbacdad9510111a45b802e40b9d3784bf78afd97510d3b", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "org.label-schema.schema-version": "= 1.0 org.label-schema.name=CentOS Base Image org.label-schema.vendor=CentOS org.label-schema.license=GPLv2 org.label-schema.build-date=20180402" } }, "Architecture": "amd64", "Os": "linux", "Size": 218612650, "VirtualSize": 218612650, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/e8751f2cdaa5067e677ec75eef6654a925bfdd02836eaa812da8b746a8a76a89/diff", "MergedDir": "/var/lib/docker/overlay2/f4933b5a2a672c2822570968d234404b88906a32c96d726e09086b7bc0c55e23/merged", "UpperDir": "/var/lib/docker/overlay2/f4933b5a2a672c2822570968d234404b88906a32c96d726e09086b7bc0c55e23/diff", "WorkDir": "/var/lib/docker/overlay2/f4933b5a2a672c2822570968d234404b88906a32c96d726e09086b7bc0c55e23/work" }, "Name": "overlay2" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:43e653f84b79ba52711b0f726ff5a7fd1162ae9df4be76ca1de8370b8bbf9bb0", "sha256:8e6ed4f4ff9f4d018baf01b862ffcc439a0e06d8255f908f6e5d111924c06b05" ] }, "Metadata": { "LastTagTime": "2018-05-24T17:25:37.103458712+09:00" } } ]

上記のdocker inspectの状況を確認する限り、該当のイメージにはip addressは付与されていませんでした
そもそもなのですが、Dockerfileで
FROM centos:7
とすると、pullされてくるDockerimageに関しては、dhcp自体が稼働をしていないので、ipアドレスがdhcpとして取得できず、errorになっているのではないかと推測しています

ただ、この時に疑問点としては、docker hostをbridge modeにせずにdocker0をを利用しして、外部のネットワークと接続する際には、問題なくcentos:7のイメージでip addressが取得できるのが疑問点として残ってしまいます

基本的なdockerの振る舞いかしれないのですが、ご教示いただけますと幸いです
よろしくお願い申し上げます

投稿2018/05/25 00:32

tetuya0703

総合スコア7

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

tetuya0703

2018/05/25 00:37 編集

TaichiYanagiyaさん ご指導ありがとうございます TaichiYanagiyaさんがご指摘をされている通り、私も同様の問題を考えました docker buildで失敗をしたイメージを、以下のようにコンテナ化をして内容を確認してみました ``` 1. docker commit "container-id" builddebug 2. docker run --rm -it builddebug /bin/bash ``` 上記の通り、docker buildが失敗をしたものを一時期的にイメージかしてcontainerにログインをして状況を確認してみました。所がdefaultのcentos:7のイメージではifconfig及びipコマンド等が実行をすることができないので、実際にbuilddebugのイメージにIP Addressが付与されているか確認をすることが出来ませんでした 他にbuilddebugのイメージの状態を確認をする方法として、docker inspectを利用してbuilddebugの状況を確認すると、以下のような状況でした ``` [ { "Id": "sha256:53230d24aa6a9668943c044d6c588e05d2a179289798704c03b9c00661458e3e", "RepoTags": [ "builddebug:latest" ], "RepoDigests": [], "Parent": "sha256:9075f4007389767910cbacdad9510111a45b802e40b9d3784bf78afd97510d3b", "Comment": "", "Created": "2018-05-24T08:25:37.096187964Z", "Container": "93f32dd6501f8488e9a55e71383b4c6180f70442a454493351aef1ab1929cc39", "ContainerConfig": { "Hostname": "93f32dd6501f", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "/bin/sh", "-c", "yum -y install initscripts MAKEDEV" ], "ArgsEscaped": true, "Image": "sha256:9075f4007389767910cbacdad9510111a45b802e40b9d3784bf78afd97510d3b", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "org.label-schema.schema-version": "= 1.0 org.label-schema.name=CentOS Base Image org.label-schema.vendor=CentOS org.label-schema.license=GPLv2 org.label-schema.build-date=20180402" } }, "DockerVersion": "18.03.1-ce", "Author": "", "Config": { "Hostname": "93f32dd6501f", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "/bin/sh", "-c", "yum -y install initscripts MAKEDEV" ], "ArgsEscaped": true, "Image": "sha256:9075f4007389767910cbacdad9510111a45b802e40b9d3784bf78afd97510d3b", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "org.label-schema.schema-version": "= 1.0 org.label-schema.name=CentOS Base Image org.label-schema.vendor=CentOS org.label-schema.license=GPLv2 org.label-schema.build-date=20180402" } }, "Architecture": "amd64", "Os": "linux", "Size": 218612650, "VirtualSize": 218612650, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/e8751f2cdaa5067e677ec75eef6654a925bfdd02836eaa812da8b746a8a76a89/diff", "MergedDir": "/var/lib/docker/overlay2/f4933b5a2a672c2822570968d234404b88906a32c96d726e09086b7bc0c55e23/merged", "UpperDir": "/var/lib/docker/overlay2/f4933b5a2a672c2822570968d234404b88906a32c96d726e09086b7bc0c55e23/diff", "WorkDir": "/var/lib/docker/overlay2/f4933b5a2a672c2822570968d234404b88906a32c96d726e09086b7bc0c55e23/work" }, "Name": "overlay2" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:43e653f84b79ba52711b0f726ff5a7fd1162ae9df4be76ca1de8370b8bbf9bb0", "sha256:8e6ed4f4ff9f4d018baf01b862ffcc439a0e06d8255f908f6e5d111924c06b05" ] }, "Metadata": { "LastTagTime": "2018-05-24T17:25:37.103458712+09:00" } } ] ``` 上記のdocker inspectの状況を確認する限り、該当のイメージにはip addressは付与されていませんでした そもそもなのですが、Dockerfileで FROM centos:7 とすると、pullされてくるDockerimageに関しては、dhcp自体が稼働をしていないので、ipアドレスがdhcpとして取得できず、errorになっているのではないかと推測しています ただ、この時に疑問点としては、docker hostをbridge modeにせずにdocker0をを利用しして、外部のネットワークと接続する際には、問題なくcentos:7のイメージでip addressが取得できるのが疑問点として残ってしまいます 基本的なdockerの振る舞いかしれないのですが、ご教示いただけますと幸いです よろしくお願い申し上げます
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問