スポンサーリンク
スポンサーリンク

dockerとdocker composeでビルドの挙動が違う?

プログラミング
スポンサーリンク
スポンサーリンク

環境

Ubuntu 22.04.01 LTS
docker v20.10.20
docker compose v2.12.0

何が起きたか

docker buildをしたときは、buildができるが、docker compose buildをすると pipの部分でエラーになる。

$ docker compose build --no-cache
[+] Building 9.8s (8/8) FINISHED                                                                                                                                                                                                                                                                               
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                      0.0s
 => => transferring dockerfile: 31B                                                                                                                                                                                                                                                                       0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                         0.0s
 => => transferring context: 2B                                                                                                                                                                                                                                                                           0.0s
 => [internal] load metadata for docker.io/library/python:3.10.8                                                                                                                                                                                                                                          0.0s
 => [1/4] FROM docker.io/library/python:3.10.8                                                                                                                                                                                                                                                            0.0s
 => [internal] load build context                                                                                                                                                                                                                                                                         0.0s
 => => transferring context: 6.93kB                                                                                                                                                                                                                                                                       0.0s
 => CACHED [2/4] WORKDIR /app                                                                                                                                                                                                                                                                             0.0s
 => [3/4] COPY . .                                                                                                                                                                                                                                                                                        0.1s
 => ERROR [4/4] RUN pip install -r requirements.txt                                                                                                                                                                                                                                                       9.6s
------                                                                                                                                                                                                                                                                                                         
 > [4/4] RUN pip install -r requirements.txt:                                                                                                                                                                                                                                                                  
#0 1.903 WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f8267d5fee0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/requests/                                                                                                                                                                                                                                                                                       
#0 2.404 WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f8266ab0ca0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/requests/                                                                                                                                                                                                                                                                                       
#0 3.406 WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f8266ab1510>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/requests/
#0 5.409 WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f8266ab2650>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/requests/
#0 9.415 WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f8266ab3610>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/requests/
#0 9.430 ERROR: Could not find a version that satisfies the requirement requests (from versions: none)
#0 9.430 ERROR: No matching distribution found for requests
#0 9.465 WARNING: There was an error checking the latest version of pip.
------
failed to solve: executor failed running [/bin/sh -c pip install -r requirements.txt]: exit code: 1
$ docker build .
Sending build context to Docker daemon  11.78kB
Step 1/5 : FROM python:3.10.8
 ---> f05c8762fe15
Step 2/5 : ENV PYTHONIOENCODING utf-8
 ---> Using cache
 ---> 063aad4327f6
Step 3/5 : WORKDIR /app
 ---> Using cache
 ---> 83adc70ffa60
Step 4/5 : COPY . .
 ---> 7d84ec20666e
Step 5/5 : RUN pip install -r requirements.txt
 ---> Running in c9fd4c613587
(省略)
[notice] A new release of pip available: 22.2.2 -> 22.3
[notice] To update, run: pip install --upgrade pip
Removing intermediate container c9fd4c613587
 ---> 7e3bded3d083
Successfully built 7e3bded3d08

修正

compose.ymlを編集したら動いた。

元々

  app:
    build: ./app

書き換え後

  app:
    build:
      context: ./app
      network: host

buildの時に、networkつながってないんやろうなぁと思って適当に足したわけだが、こんな挙動でしたっけ?記憶がない。

動いたからいいんだけど、compose specは理解した方がいいのだろうか。

プログラミング
スポンサーリンク
スポンサーリンク
スポンサーリンク
びぼうろく

コメント

タイトルとURLをコピーしました