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.
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.
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.
It wasn't Stapa Saito Maji Respect, but I could only think of such a title without a joke.
Recommended Posts