Skip to content

Instantly share code, notes, and snippets.

@philcrissman
Created June 14, 2019 20:54
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 philcrissman/fce852472475011ef5e881b2da0839bb to your computer and use it in GitHub Desktop.
Save philcrissman/fce852472475011ef5e881b2da0839bb to your computer and use it in GitHub Desktop.
Attach to a docker container with less typing
#!/usr/bin/env ruby
class DockerAttacher
attr_reader :docker_container
def initialize(docker_container)
if docker_container.nil?
puts "Usage: dock [container_id]\nGet container id with `docker ps`"
else
@docker_container = docker_container
end
end
def attach!
return unless docker_container
attach_to_docker_container
end
private
def attach_to_docker_container
exec("docker exec -it #{docker_container} /bin/bash")
end
end
DockerAttacher.new(ARGV[0]).attach!
@tonyc
Copy link

tonyc commented Jun 14, 2019

dock() {
  docker exec -it $1 /bin/bash
}

:)

@philcrissman
Copy link
Author

philcrissman commented Jun 14, 2019

Yeah using ruby and creating a class is overkill. ¯\_(ツ)_/¯

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