Home>

I was trying to study Docker, trying to build a docker environment using rails and checking the behavior, but I am having trouble because of an error.

Referenced articles
https://qiita.com/Nishi53454367/items/aee4cf0c346bc115be99#comments

Error resolution

Starting docker_sample_db_1 ... error
ERROR: for docker_sample_db_1 Cannot start service db: Mounts denied: approving/Users/aaa/docker_sample/tmp/db: file does not exist
ERROR: for db Cannot start service db: Mounts denied: approving/Users/aaa/docker_sample/tmp/db: file does not exist
ERROR: Encountered errors while bringing up the project.
Corresponding source code

The source code is shown in the directory diagram.

docker_sample
├ mysql-confd
│ └default_authentication.yml
├ src
│ ├ Gemfile
│ └ Gemfile.lock
│
├ docker-compose.yml
└ Dockerfile
Gemfile
#frozen_string_literal: true
source "https://rubygems.org"
git_source (: github) {| repo_name | "https://github.com/#{repo_name}"}
gem'rails'
#No description
# docker-compose.yml format version specification
version: '3'
services: services:
  # Rails container definition
  web:
    # Build image using Dockerfile
    build: ..
    #Default command when starting a container
    #Port number: 3000
    # IP address to bind: 0.0.0.0
    # Rails server responds when port 3000 arrives
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    #Mount local src in container
    volumes:
      --./src:/app
    # Publish number 3000 outside the container
    #Public port number: Forwarding port number inside the container
    ports: ports:
      --3000: 3000
    #db container set to start first
    depends_on:
      --db
    Set to debug using #pry
    tty: true
    stdin_open: true
  #MySQL container definition
  db:
    #Create container using mysql
    image: mysql: 5.7
    volumes:
      Set the default authentication format for # Mysql8.0 to mysql_native_password
      --./mysql-confd:/etc/mysql/conf.d
      # Mount the locally held DB in the container
      --db-volume:/var/lib/mysql
    # Define environment variables in the container
    environment: environment:
      # mysql root user password setting
      MYSQL_ROOT_PASSWORD: password
# Keep DB contents locally
volumes:
  db-volume:
#Dockerfile for Rails container
#Specify Ruby2.5.1 as the baseline of the image
FROM ruby: 2.6.5
#Install required packages for Rails
RUN apt-get update -qq&&apt-get install -y build-essential nodejs
#Create root directory
RUN mkdir/app
#Specify working directory
WORKDIR/app
# Copy local Gemfile and Gemfile.lock
COPY src/Gemfile/app/Gemfile
COPY src/Gemfile.lock /app/Gemfile.lock
# Gem installation execution
RUN bundle install
#Copy local src
COPY src/app
What I tried (hypothesis I made)

This error says "db: file does not exist"
Oh, I guess it means that there is no file, but I wonder what kind of file I need to create. But I don't know where to look.

I was also doing something less productive by changing the mysql version of docker-compose.yml.

Other things I tried (from the edit request)
docker-compose down --rmi all --volumes --remove-orphans


With this, I deleted all the containers including image and tried again from the beginning.
The result didn't change ...

Supplementary information (FW/tool version, etc.)

ruby 2.6.5
docker 20.10.0
docker-compose 1.27.4