下記のようなエラーに出くわしたので備忘録。
mbp:sample_app kentaroyoshizumi$ docker-compose run web rails new . --force --database=mysql --skip-bundle
Pulling db (mysql:8.0)...
8.0: Pulling from library/mysql
4be315f6562f: Already exists
96e2eb237a1b: Already exists
8aa3ac85066b: Already exists
ac7e524f6c89: Already exists
f6a88631064f: Already exists
15bb3ec3ff50: Already exists
ae65dc337dcb: Already exists
573c3c7fa18d: Pull complete
9d10771b98b8: Pull complete
3d8ef442614b: Pull complete
7dc17a6cea26: Pull complete
752752efdaea: Pull complete
Digest: sha256:2dafe3f044f140ec6c07716d34f0b317b98f8e251435abd347951699f7aa3904
Status: Downloaded newer image for mysql:8.0
Building web
Traceback (most recent call last):
File "compose/cli/main.py", line 81, in main
File "compose/cli/main.py", line 203, in perform_command
File "compose/metrics/decorator.py", line 18, in wrapper
File "compose/cli/main.py", line 968, in run
File "compose/cli/main.py", line 1426, in run_one_off_container
File "compose/project.py", line 664, in up
File "compose/service.py", line 364, in ensure_image_exists
File "compose/service.py", line 1111, in build
File "compose/service.py", line 1841, in build
compose.service.BuildError: (<Service: web>, {'message': 'dockerfile parse error line 4: unknown instruction: //'})
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "docker-compose", line 3, in <module>
File "compose/cli/main.py", line 92, in main
TypeError: can only concatenate str (not "dict") to str
[93647] Failed to execute script docker-compose
結論Dockerfile内のコマンドの記述が誤っていた。
FROM ruby:2.5
RUN apt-get update -qq && \ //←バックスラッシュが抜けていたり、コメントアウトがきいていなかったりする。
apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp
ここを修正してうまく構築できた。