This is the first post in the More than "Hello World" in Docker series. The series will help you ready your app: from setting it up locally to dep...
For further actions, you may consider blocking this person and/or reporting abuse
Thank you for sharing, Raphael. One point - you don't need to set autoload_paths because of all the directories under
app
are loaded by Rails by default. See guides.rubyonrails.org/v5.2/autolo....Thanks for the tip Serguei! :D I'll try that out in my Rails 5.2 setup
Hi Raphael, thanks for writing this up! I made it all the way to the end but when I click any of the links on the page the number doesn't increment and I get the following message on the server. However when I reload the page the number does appear to be incremented.
web_1 | Started POST "/increment_async?post_id=3" for 172.19.0.1 at 2019-11-14 16:13:27 +0000
web_1 | Cannot render console from 172.19.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
web_1 | Processing by HomeController#increment_async as HTML
web_1 | Parameters: {"authenticity_token"=>"nJyVPYC66u05NEifhJpSU8j45OihvALWatPZded9kBbveo8I463AVM9+XjHiOABKtnh9FvjxAfOkcbdC1oEhiA==", "post_id"=>"3"}
sidekiq_1 | 2019-11-14T16:13:27.719Z pid=1 tid=gs60ykwsh class=IncrementCountWorker jid=ff410d219f7e7968abf5a765 INFO: start
sidekiq_1 | 2019-11-14T16:13:28.145Z pid=1 tid=gs60ykwsh class=IncrementCountWorker jid=ff410d219f7e7968abf5a765 elapsed=0.424 INFO: done
web_1 | No template found for HomeController#increment_async, rendering head :no_content
web_1 | Completed 204 No Content in 1241ms (ActiveRecord: 0.0ms)
Hi Tom,
Thank you for reading through the article, and providing me with this feedback. I have update the article with the answer to your question. I also included the answer below for easier reference
In step 7.5, copy-paste this snippet instead. This adds the line
redirect_to root_path
in the controller function increment_async so it goes to the homepage once the link is pressed.Excellent, thanks Raphael!
Adding
sidekiq
andweb
at docker-compose.yml will build twice when you rundocker-compose build
The building process is slow. Is there anything can we improve here?
Hi Allen, that's an interesting observation.
Indeed, the build process will be slow especially on the 1st run. This is because our Dockerfile uses the base image "ruby:2.5.1-slim". This base image itself consists of many other images that include individual parts of the system (like its slim OS).
Docker is smart in that it creates a "reusable layer" for each line in your Dockerfile. It is also intelligent enough to detect if you made changes in your system with respect to those commands. If no change has been made with respect to that line in your Dockerfile, it just reuses that layer as part of your image.
Also, ran for the 1st time, it also runs the 2nd command in the Dockerfile:
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs libsqlite3-dev
. This updates apt and install critical dependencies. This indeed takes awhile. In one of the demoes I did, it downloaded 250MB worth of packages from the internet.After the 1st run, all you change is your code (and maybe adding Gems in your Gemfile here and there). Your
docker build
will hopefully be much faster (unless you changed a big part of your app).As per Sidekiq and Web having separate images, it might be that they are just tagged under different names. You can check if their image hash (it looks like this: c12dasd21c) are the same. If they are, they are using the same image. And even if they are using different images, you can check that they use command Docker image layers via
docker history <chash>
and they have at least some common docker image layers.Hi Raphael, how you're doing?
I have a problem for execute sidekiq in my app, I hope you can help me.
I created a container for execute sidekiq from sidekiq-entrypoint.sh. After executing the docker-compose up rails command, I check the created containers and I get:
CONTAINER ID--------- IMAGE
282afcb874ef-------------legacy_sidekiq
COMMAND-------------------CREATED-----------STATUS
"./sidekiq-entrypoin…"-----6 minutes ago-------Up 6 minutes
PORTS--------------------------NAMES
0.0.0.0:8081->8080/tcp-----legacy_sidekiq_1
Also, I try to access the sidekiq dashboard through 0.0.0.0:8081/sidekiq or 0.0.0.0:8080/sidekiq, but I get 'Not found'.
My routes:
require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'
If you need other data, I will be attentive.
Such a thorough explanation about Docker. Looking forward to the next posts in this series, particularly the automatic deploys!
Raphael, what is
RAILS_ENV: "docker_development"
defined in the docker-compose.yml file?Hi Serguei, I made a mistake there. You must change it to "development" for it to work. I revised my article. Thank you for the feedback :D
Yeah, thank you, that's what I believed it to be.
Hey man, this is great! I have been struggling to even get a task executing and this was exactly what I neded. Just one question: what is in docker_puma.rb? I have a puma.rb and I think it should be sufficient, trying to understand what we would want in a docker_puma.rb
Hi Daniel, yup there shouldn't be any difference. I just copied
docker_puma.rb
frompuma.rb
. It just lets me specify a different configuration for (a) when puma is running in my local, (b) and for when puma is running on ECS. But there shouldn't be any problem if you decide to justpuma.rb
for both (for now).Hello Raphael, great tutorial thanks so much. I don't have a lot of experience with docker, Sidekiq and Redis. Following the tutorial I ran into this error (Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) ) when clicking the "Like" link in the Rails app. It seems that the Redis URL is incorrect, it is looking for Redis in the "web" container. Any help would be greatly appreciated!!
This needs way more post reactions. Great content, my dude.
Thank you Henry! :D
Wonderful work Raphael, great detail that is so helpful!
Thank you Rory! :D
This is one of the best tech articles I have ever read. I was able to get AWS setup on ECS stack because of this series of articles.
Thanks for writing such detailed series mate.
Good write. And - IS fargate coming soon? :)
Excellent article and I would like know the approximate cost for this setup so this would help me