環境
WSL2 ubuntu20.04.5LTS
発生している問題・エラーメッセージ
dockerでコンテナのフォルダをホストにマウントして、ホスト上でマウントしたフォルダの内容に変更を加えようとするとパミッションエラーが出たので
ホスト上のユーザーのuidとgidをコンテナ上のユーザーのuidとgidと合わせようと思いDockerfileを編集したところ
docker compose up -d でapi_containerが立ち上がらなくなりました。
docker-compose.yml
version: '3.9' services: web: image: nginx:1.23-alpine container_name: web_contianer env_file: - web.env ports: - "8000:8080" volumes: - public-data:/app/public - tmp-data:/myapp/public - ./config/nginx:/etc/nginx/conf.d depends_on: frontend: condition: service_healthy api: condition: service_healthy db: image: mysql:8.0 container_name: db_contianer env_file: - db.env ports: - "3306:3306" volumes: - db-data:/var/lib/mysql - ./config/mysql:/etc/mysql healthcheck: test: ["CMD", "pwd"] interval: 1s timeout: 1s retries: 3 start_period: 1s frontend: build: context: ./frontend dockerfile: Dockerfile target: ${BUILD_MODE} container_name: front_contianer env_file: - ./frontend/front.env ports: - "3000:3000" volumes: - public-data:/app/build healthcheck: test: ["CMD", "pwd"] interval: 1s timeout: 1s retries: 3 start_period: 1s tty: true stdin_open: true api: build: context: ./backend dockerfile: Dockerfile container_name: api_contianer env_file: - ./backend/api.env ports: - "4000:4000" volumes: - tmp-data:/app/tmp - log-data:/app/log - ./backend:/app depends_on: db: condition: service_healthy healthcheck: test: ["CMD", "pwd"] interval: 1s timeout: 1s retries: 3 start_period: 1s tty: true stdin_open: true volumes: db-data: driver: local public-data: tmp-data: log-data:
Dockerfile(api_container用)
FROM ruby:3.1.2-slim AS dev ARG USER_NAME WORKDIR /app COPY Gemfile Gemfile.lock . RUN apt-get -y update &&\ apt-get -y install \ default-mysql-client \ default-libmysqlclient-dev \ gcc \ libc-dev \ make \ ruby-dev RUN bundle install COPY . . COPY entrypoint.sh /usr/bin/ RUN chmod +x /usr/bin/entrypoint.sh ENTRYPOINT ["entrypoint.sh"] EXPOSE 4000
entrypoint.sh
**#!/bin/bash** set -e useradd -u ${USER_ID} -m ${USER_NAME} groupmod -g ${GROUP_ID} ${GROUP_NAME} export HOME=/home/${USER_NAME} rm -f /app/tmp/pids/server.pid exec "$@"
いろいろ調査したところapi_containerのDockerfileの
ENTRYPOINT ["entrypoint.sh"]
の記述がなければ正常に動きます。
またentrypoint.shのファイルの内容は正常であり、entrypoint.shファイルの内容を何も記述しなくてもコンテナが起動しません。
一度起動したコンテナを削除せずにもう一度docker compose upコマンドを実行すると
user already exist となり、api_containerが起動できなくなるので
entrypoint.shのuseraddなどのコマンドは実行されています。(環境変数も問題なく渡せています。)
log
docker compose upに出てくるログは
api_containerについては
container for service "api" is unhealthy api_contianer exited with code 0
のみでありここから先がデバッグできない状態です。
ご教授お願い致します。

回答1件
あなたの回答
tips
プレビュー