Skip to content

Instantly share code, notes, and snippets.

@TimothyClayton
Created April 10, 2017 20:06
Show Gist options
  • Save TimothyClayton/c7c919bd5a7f1667c91e8131729c59d4 to your computer and use it in GitHub Desktop.
Save TimothyClayton/c7c919bd5a7f1667c91e8131729c59d4 to your computer and use it in GitHub Desktop.
Docker commands

curl $(docker-machine ip default):3000

When in Tanker

List containers: sudo docker ps

Shell access to running container sudo docker exec -it <container name> bash

Access psql psql -h 10.0.0.1 -U postgres -d prod_master

Starty Commands

Build an image:
docker build -t timothyclayton/docker_what:red .

Run/build a container (as a daemon with port forwarding):
docker run -d -p 3001:3000 timothyclayton/docker_what:red

Containers

List docker containers:
docker ps -a

Remove a docker container:
docker rm <container_name>

Remove all containers:
docker rm $(docker ps -aq)

Images

Remove containers before images...

List docker images:
docker images

Remove a docker image:
docker rmi <image id>

Remove ALL docker images:
docker rmi $(docker images -q)

Sample Docker file for app named docker_what:

FROM ruby:2.2.2

# Run updates
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev

# Set up directory
RUN mkdir /docker_what

# Add the rest of our app's code
WORKDIR /docker_what
ADD Gemfile /docker_what/Gemfile
ADD . /docker_what

# Set up gems...there is a way to do this so it doesn't reinstall gems that haven't changed
RUN bundle install

# Clean up APT when done.
# RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Set ENV if needed
# ENV MONGOID_ENV staging
# ENV RAILS_ENV staging

# For port forwarding to local machine (mac)
EXPOSE 3000
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment