DEV Community

Cover image for Dockerize the multi-services application for local development

Dockerize the multi-services application for local development

Dmitry Salahutdinov on April 15, 2019

As nowadays many complex web-applications run on production containerized, we keep developing them in 'old-school' way, installing the Postgresql, ...
Collapse
 
alexanderrykhlitskiy profile image
Alexander Rykhlitskiy •

One more question if you don't mind. As far as I see from "- .:/app:cached", you use mac. Do your coworkers use Linux?
I'm asking because running "run" on Linux without "--user" option creates files with "root" owner. And running without this option raises error because of "- BUNDLE_PATH=/bundle". It's not allowed to write to root folder for non root users.
Do you solve it somehow? Or your entire team uses mac?

Thanks

Collapse
 
dsalahutdinov profile image
Dmitry Salahutdinov Amplifr.com •

For now, I do not have such problems, because of mac.
I think you could change BUNDLE_PATH for something less like '/app/bundle' not to be a root directory?

Do you also consider to run the docker as non-root user for linux?

Collapse
 
alexanderrykhlitskiy profile image
Alexander Rykhlitskiy • • Edited

like '/app/bundle'

Yes, I do it this way now, but annoying bundle folder (though empty) gets created in app directory on host. And still no luck because bundler says / is not writable.

Do you also consider to run the docker as non-root user for linux?

You mean docker command? I run it as non-root, but there's still this issue on Linux github.com/docker/compose/issues/1...

My last set of questions :)

  1. Why do you need to set BUNDLE_PATH both in Dockerfile.dev and docker-compose.yml?
  2. When do you run bundle install? I cannot find it here gist.github.com/dsalahutdinov/2d89...

Thanks a lot for your answers!

Thread Thread
 
dsalahutdinov profile image
Dmitry Salahutdinov Amplifr.com •

Thanks for the questions, they are really make sense!

1) seems setting it in docker-compose is redundant
2) most suitable place, I think, is to leave the bundle install at bin/setup where it usually is, like here github.com/thepracticaldev/dev.to/...

Collapse
 
alexanderrykhlitskiy profile image
Alexander Rykhlitskiy •

Thanks for great article! Just one small note. You mentioned example of running rake task

docker-compose up runner bundle exec rake db:create

Shouldn't it be "run" instead of "up"?

Collapse
 
dsalahutdinov profile image
Dmitry Salahutdinov Amplifr.com •

Yep, Alexarder, this is good point! fixed

Collapse
 
kamalhm profile image
Kamal •

This is interesting but I find it hard to follow, if someday you write a simpler docker tutorial, I'll be so happy :D

Collapse
 
chamnap profile image
Chamnap Chhorn • • Edited

Nice article!

I'm curious about puma/sidekiq. Let's say I want to spawn them few processes, how could I do it?

Collapse
 
dsalahutdinov profile image
Dmitry Salahutdinov Amplifr.com •

Hi!
There is no problem, just run puma -w 2 or sidekiq -c 2 or whatever you want
But in most cases 1 worker is enough for local development

Collapse
 
binary_maps profile image
Jadran Mestrovic •

Docker network architecture covers all network scenarios required for successful communication at the local, remote or cluster level.

Collapse
 
viccw profile image
Vic Seedoubleyew •

Thanks a lot for this article, it was very interesting!

I think it would benefit from having an improved English, it would make it a lot easier to read.

Thanks again though!

Collapse
 
dsalahutdinov profile image
Dmitry Salahutdinov Amplifr.com •

Thanks, try to make it better :)

Collapse
 
rommik profile image
Roman Mikhailov •

Great Article! How do you debug and create code break points in the runtime. Maybe you could devote a section on this topic?

Collapse
 
alexanderrykhlitskiy profile image
Alexander Rykhlitskiy • • Edited

There are two options using binding.pry:

1) Attach to running server container after hitting pry with

docker attach $(docker-compose ps | grep app_1 | awk '{print $1}')
Enter fullscreen mode Exit fullscreen mode

2) Run server with this command instead of docker-compose up

docker-compose run --service-ports app /bin/sh -c "rm -f tmp/pids/server.pid && rails s -b 0.0.0.0"
Enter fullscreen mode Exit fullscreen mode