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

More than 1 year has passed since last update.

【Docker】Dockerfileで親ディレクトリを参照する方法

Last updated at Posted at 2022-03-23

はじめに

 本記事は、プログラミング初学者、学習を進めていて疑問に思った点について調べた結果を備忘録も兼ねてまとめたものです。
 そのため、記事の内容に誤りが含まれている可能性があります。ご容赦ください。
 間違いを見つけた方は、お手数ですが、ご指摘いただけますと幸いです。

Dokerfileで親ディレクトリを参照する方法

Dokerfileで親ディレクトリを参照するにはDocker-composeのbuildの箇所でcontextとdockerfileを指定します。

docker-compose.yml
version: '3.9'
services:
  api:
    build:
      context: .
      dockerfile: ./docker/api/Dockerfile
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    # restart: on-failure
    volumes:
      - .:/myapp
    environment:
      RAILS_ENV: ${APP_ENV}
    ports:
      - "${API_PORT}:3000"
    depends_on:
      db:
        condition: service_healthy

Dockerfileには親ディレクトリから見たパスを記述します。

Dockerfile
FROM ruby:3.1.1

WORKDIR /myapp

COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock  /myapp/Gemfile.lock
RUN bundle install

COPY docker/api/entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]

EXPOSE 3000

ENV TZ=Asia/Tokyo

CMD ["rails", "server", "-b", "0.0.0.0"]
1
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
1
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?