[RUBY] You there who want to launch Rails on both the host and the client with Docker Compose!

what's this?

I don't think so much, but when you're using Docker Compose with Rails, do you want to start the Rails server on the host and client sides? In my case, I couldn't find a way to run System Test only in the Docker environment, so in my case I would like to run Rails in the Ubuntu environment and run the other system tests in a container inside Docker. Therefore, such an environment was needed. The problem with trying to do that was that the files created in (Rails root) / tmp / conflicted on the host side and the client side and couldn't be started at the same time. In such a case, the clue that I could read and solve was "How to exclude a part when mounting Volume with Docker", so I myself I will leave the trajectory here.

What are you doing?

The point is that Rails cannot be started at the same time because the tmp folder exists. Without it, you can boot, regardless of port conflicts. The point is that we should have a sparse relationship with each other. That is, the client and host tmp folders should not be in sync. The code below prevents only the tmp folder from palpitating with the host.

version: '3'

volumes:
  rails_tmp_data:
    
services:
  as:
    build:
      context: ./
    ports:
      - 3333:3000
    volumes:
      - ./:/usr/src/app/
      - rails_tmp_data:/usr/src/app/tmp/
    command: 
      /bin/sh -c "yarn install --check-files && bundle install && rails db:create && rails db:migrate && rm -f /usr/src/app/tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0' --early-hints"

The above code is limited to the main points. Therefore, please note that it does not work with copy and paste.

That's it

I broke the port settings. I won't write about it here. Writing an article on the way became a hassle. Please do something about it. That's right.

About the title

It wasn't Stapa Saito Maji Respect, but I could only think of such a title without a joke.

Recommended Posts

You there who want to launch Rails on both the host and the client with Docker Compose!
read the tag assigned to you on ec2 with boto3
Get the host name of the host PC with Docker on Linux
For those of you who don't know how to set a password with Jupyter on Docker
When you want to adjust the axis scale interval with APLpy
Put Cabocha 0.68 on Windows and try to analyze the dependency with Python
Connect to VPN with your smartphone and turn off / on the server
If you want to include awsebcli with CircleCI, specify the python version
Add 95% confidence intervals on both sides to the diagram with Python / Matplotlib
When you want to change the HTTP headers of Flask's test client
I want to analyze the emotions of people who want to meet and tremble
Launch Flask application with Docker on Heroku
Join Azure Using Go ~ For those who want to start and know Azure with Go ~
For those who want to learn Excel VBA and get started with Python
What you want to memorize with the basic "string manipulation" grammar of python
If you want to enter the virtual environment with jupyter, nb_conda_kernels is recommended