Skip to content

Instantly share code, notes, and snippets.

@saiqulhaq
Created June 15, 2019 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saiqulhaq/3189cbbbb587d4b28b7f7dd6b56b8112 to your computer and use it in GitHub Desktop.
Save saiqulhaq/3189cbbbb587d4b28b7f7dd6b56b8112 to your computer and use it in GitHub Desktop.
Docker and Rails tips

2 months ago I got "Docker for Rails Developer" book. It's easy to follow step by step for beginner.

However I haven't try it for production purpose, because my projects are not ready yet to use Docker for production. There will many changes on assets, database, and caching system. So I use it for development environment only till now.

After few days learning this Docker thing, I found great gem to build Dockerfile and docker-compose.yml files rails. The gem is dockrails, it uses unison to sync your files.

If I could give a recommendation for you, I would recommend you to read "Docker for Rails Developer" book first, try to use it on new rails app, then use dockrails, so it will be easy when you struggle when setting up the env.

Following is my cheatsheet, maybe it would useful for you :)

list image

docker images

list container

docker ps -a

execute a command inside a container

docker run ruby:2.6 ruby -e "puts :hello"
docker run --rm ruby:2.6 ruby -e "puts :hello"
docker run -i -t --rm -v ${PWD}:/usr/src/app ruby:2.6 bash
docker run -p 3000:3000 image_id bin/rails s -b 0.0.0.0

list running containers

docker ps -a

build

docker build .

delete container

docker rm container_id1 container_id2

delete all unused volumes

docker system prune --volumes

remove all stopped containers

docker container prune

Remove dangling and unused images

docker image prune -a

How to shutting down dockrails?

For me, when I send SIGINT (Ctrl+C) command, usually the database data is not saved in Docker's volume, so database data is lost.To prevent that I use "docker-compose down" command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment