Created
November 26, 2019 14:00
-
-
Save giladshanan/c2e8e91f27e04109e92cd73f4f3d0872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This goes in .bashrc, .zshrc, or wherever you like to store your aliases. | |
# Frequently used functions that I don't want to memorize/type: | |
alias dc="docker-compose " | |
# run bash in the app container | |
alias dc-bash="dc exec app bash" | |
# run rails console in the app container | |
alias dc-rc="dc exec app bundle exec rails c" | |
# run rspec in the app container | |
alias dc-rspec="dc exec app bundle exec rspec " | |
# If you miss `be rails s`: | |
# Bring up all containers in the background and | |
# attach to app so I can just see the app server log and use pry | |
function dc-start() { | |
dc up -d; | |
dc-attach; | |
} | |
# To restart the server: | |
# Restart the app container and | |
# attach to app so I can just see the app server log and use pry | |
function dc-restart() { | |
dc restart app; | |
dc-attach; | |
} | |
# Using Pry: | |
# Note: This is @rdunlop's solution, I just added a small change. | |
# To access interactive pry sessions, | |
# find a docker container, and attach to it. | |
# Ctrl-P/Ctrl-Q is the default way to detach, | |
# but most people think that Control-C should do it, so we set that | |
# Ref: https://docs.docker.com/engine/reference/commandline/attach | |
# | |
# Note: in order to attach to a container, you must have it started | |
# with docker-compose settings: | |
# app: | |
# tty: true | |
# stdin_open: true | |
# Use dc-attach to attach to the app service. | |
# To attach to another service, pass in the name | |
# (use dc-attach db to attach to the db service). | |
function dc-attach() { | |
service=${1-'app'} | |
docker attach $(docker-compose ps -q $service) --detach-keys="ctrl-c"; | |
} | |
# list the names of services defined in docker-compose.yml, so you can attach to them | |
alias dc-services="dc config --services" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment