Skip to content

Instantly share code, notes, and snippets.

@zotherstupidguy
Last active May 1, 2018 15:36
Show Gist options
  • Save zotherstupidguy/e20938d753955b13e981bbe6119b5f9e to your computer and use it in GitHub Desktop.
Save zotherstupidguy/e20938d753955b13e981bbe6119b5f9e to your computer and use it in GitHub Desktop.
Docker & Docker-Compose Cheatsheet
#!/bin/bash
#In amazon linux, Create a Docker group section it is neccesary add user to docker group:
sudo usermod -aG docker $(whoami)
# Build an image
docker build -f DOCKERFILE -t image_name .
# Run a container
docker run -it -p HOSTPORT:CONTAINER_EXPOSED_RPORT --name container_name image_name
docker run -it sonopace:api /bin/bash
# Logs
docker logs container_name
docker logs -f container_name
# Diff the changes on the filesystem of the container
docker diff container_name
# Port given the port on the container, shows the port on the host
docker port container_name container_port
# CP from the container to the host
docker cp container_name:/path/to/file /path/to/host
# inspect
docker inspect container_name
# Get container IP
docker exec CONTAINER_ID cat /etc/hosts
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
# Create a nginx image
docker pull nginx
# Run the nginx image on port 80 and name the container "proxy"
docker run -it -p 80:80 -p 443:443 --name proxy nginx:latest /bin/bash
docker run --name proxy -p 80:80 nginx
# This would direct all requests to test.com
# to the web app running in the first Docker container and
# all requests to example.com to the second Docker container.
docker run -d -p 127.0.0.1:3000:80 coreos/apache /usr/sbin/apache2ctl -D FOREGROUND
docker run -d -p 127.0.0.1:5000:80 coreos/apache /usr/sbin/apache2ctl -D FOREGROUND
# Benchmark using ApacheBench
# ab -n <num_requests> -c <concurrency> <addr>:<port><path>
ab -n 1000 -c 100 http://localhost:4567/
# Sanity check
docker run -d --name testweb -p 8989:80 nginx:alpine
# 'docker exec' will allow you to spawn a new process in the already running container.
# spawn a shell and look around. do whatever diagnosis you'd do on the thing running in the container │ ahfeel
docker exec -it <containeridorname> bash
# rackup for rack applications wouldn't bind port to eth0 without --host 0.0.0.0, instead it would bind to localhost only
# making itsel unaccessable through the host container!!
docker run -it -p 80:8888 --name $container_name $container_image bundle exec rackup -p 8888 --host 0.0.0.0
###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment