Back-end Engineering Articles

I write and talk about backend stuff like Ruby, Ruby On Rails, Databases, Testing, Architecture / Infrastructure / System Design, Cloud, DevOps, Backgroud Jobs, and more...

Twitter:
@daniel_moralesp

2020-04-17

Docker Commands Cheatsheet

1- Docker

sudo docker-compose build
sudo docker-compose up
sudo docker-compose up db
sudo docker-compose up web
sudo docker-compose up redis
sudo docker-compose up sidekiq
sudo lsof -i -P -n | grep 5432
sudo kill -9 1124
sudo docker rm /<conatineID> -f
sudo docker-compose down
sudo docker image prune
sudo docker volume prune
sudo docker container prune

2- PostgreSQL

sudo service postgresql restart

3- Databases

sudo docker-compose run web rake db:create
sudo docker-compose run web rake db:migrate
sudo docker-compose exec web rails db:migrate:status
sudo docker-compose exec web rails db:migrate:down VERSION=<version_number>
sudo docker-compose exec web rails db:rollback STEP=<number_step>
sudo docker-compose run web rake db:seed
sudo docker-compose run web rake db:test:prepare
sudo docker-compose exec web rails console
sudo docker-compose exec web rails g model <modelname> <fields>
sudo docker-compose exec web rails g migration <migration_name> <fields_to_add>
sudo docker-compose run -e "RAILS_ENV=test" web rake db:create db:migrate
sudo docker-compose run -e "RAILS_ENV=test" web rake db:seed
sudo docker-compose run -e "RAILS_ENV=test" web rails console

4- Routes

sudo docker-compose exec web rake routes

5- Tests

sudo docker-compose run web bundle exec rspec
sudo docker-compose exec web rake test (minitest)
sudo docker-compose run web bundle exec rspec spec/models
sudo docker-compose run web bin/rspec spec/models
sudo docker-compose run web bundle exec rspec spec/models/parking_fine_spec.rb
sudo docker-compose run -e COVERAGE=true web rspec spec/models/
sudo docker-compose run -e "RAILS_ENV=test" web bundle exec rspec spec/models/name.rb
sudo docker-compose run -e "RAILS_ENV=test" web bundle exec rspec spec/workers/name.rb
sudo docker-compose run web rails g rspec:model model_name
sudo docker-compose run web rails g factory_girl:model model_name
sudo docker-compose run web rails g rspec:controller controller_name
sudo docker-compose run web rails g rspec:feature feature_name
sudo docker-compose run web rails g rspec:request request_name

6- Assets

sudo docker-compose run web bundle exec rake assets:clean
sudo docker-compose run web bundle exec rake assets:precompile
sudo docker-compose run -e "RAILS_ENV=staging" web bundle exec rake assets:precompile

7- Gems

sudo docker-compose exec web bundle outdated
sudo docker-compose exec web bundle install
sudo docker-compose run web next bundle install
sudo docker-compose exec web bundle update gem_name
sudo docker-compose exec web bundle clean --force
sudo docker-compose run web next --init
sudo docker-compose run web bundle_report compatibility --rails-version=6.0.0
sudo docker-compose run -e BUNDLE_GEMFILE=Gemfile.next web bundle install

8- Tasks

sudo docker-compose run web  bundle exec rake [rake_task_name]
sudo docker-compose run web  bundle exec rake update_state_in_parking_space

9- Others

sudo atom config/application.yml
sudo atom config/database.yml
git log --follow -p -- app/controllers/reports/name.rb # to check differences in a certain file
google-chrome coverage/index.html
git branch -d branch_name
git branch -D branch_name
git push origin --delete branch_name
Binding.remote_pry #inside the code
sudo docker-compose exec web pry-remote
sudo docker-compose exec web EDITOR="code --wait" bin/rails credentials:edit
sudo docker-compose run --rm -e EDITOR="code --wait" web bin/rails credentials:edit
sudo docker-compose run web bundle exec rake tmp:cache:clear

10- Heroku

heroku run rake db:seed --app app_name
heroku run rails c --app app_name
heroku run rake assets:precompile --app app_name
heroku run rake [rake_task_name] --app app_name
heroku run rake update_state_in_parking_space --app app_name
heroku run rake db:migrate --app app_name
heroku run rake db:migrate:status --app app_name
heroku run rake tmp:cache:clear --app app_name
heroku run "bundle exec rake db:schema:dump && cat db/schema.rb" --app app_name

Original link: https://docs.google.com/document/d/1I2I97JkSYf9oOHRbxmIFTH7vdNXlSu0FPpfdIz1Tk1E/edit