0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Macで動いていたdocker containerが、Windows環境でrunに失敗した

Posted at

タイトル通り、Macで動いていたdocker containerが、Windows環境でrunに失敗しました。
docker-compose.ymlは以下。docker-compose-waitを用いてdb containerの起動待ちを行った後、migration conatianerが起動しtableのmigrationを行う仕組みです。

services:
  db:
    build:
      context: .
      dockerfile: ./images/db/Dockerfile
    volumes:
      - ./db/data:/var/lib/mysql:rw
    restart: always
    ports:
      - "3306:3306"
    env_file:
      - ./envfiles/.db
  migration:
    build:
      context: .
      dockerfile: ./images/migration/Dockerfile
    depends_on:
      - db
    command: ["upgrade head"]
    volumes:
      - ./migration/alembic:/workspace/alembic:rw
    env_file:
      - ./envfiles/.migration

Dockerfileは以下。poetryを使ってalembicをcontainerにインストールします。

FROM python:3.11-bookworm as requirements-stage
WORKDIR /tmp

RUN pip install poetry

COPY ./migration/pyproject.toml ./migration/poetry.lock* /tmp/

RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

FROM python:3.11-bookworm
WORKDIR /workspace

COPY --from=requirements-stage /tmp/requirements.txt /workspace/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /workspace/requirements.txt

ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.9.0/wait /wait
RUN chmod +x /wait

COPY ./migration/run.sh /usr/local/bin
RUN chmod +x /usr/local/bin/run.sh

COPY ./migration/alembic.ini ./

ENTRYPOINT ["run.sh"]

docker compose buildは通っているのになぜかdocker compose upで以下のようなエラーが出力されました。

migration-1        | exec /usr/local/bin/run.sh: no such file or directory

15分ほど試行錯誤しても解決策が思い浮かばなかったため、github copilot chatに助けを求めると...
image.png

どうやら改行コードの修正が必要らしいとのことでした。
半信半疑で指示通りCRLFからLFに変更すると、run.shの中身の見た目は一切変わらずdocker compose upが通りました。。。

migration-1        | [INFO  wait] Host [db:3306] is now available!
migration-1        | [INFO  wait] --------------------------------------------------------
migration-1        | [INFO  wait] docker-compose-wait - Everything's fine, the application can now start!
migration-1        | [INFO  wait] --------------------------------------------------------
migration-1        | INFO  [alembic.runtime.migration] Context impl MySQLImpl.
migration-1        | INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
migration-1        | INFO  [alembic.runtime.migration] Running upgrade  -> 61e1a7eba0f8, create_table_circle_info
migration-1        | run migraiton scripts in online mode
migration-1 exited with code 0

恥ずかしながら、OSによって改行コードが異なることを認知していませんでした。。。それが原因でfile not found errorが発生するとは、それはそれで不思議ですね。

[参考]
https://qiita.com/sbeleg_77/items/833de09f7bca24bc8ab8

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?