Skip to content

Instantly share code, notes, and snippets.

@Marak
Last active October 31, 2023 20:48
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Marak/63f437e3946805f6473a to your computer and use it in GitHub Desktop.
Save Marak/63f437e3946805f6473a to your computer and use it in GitHub Desktop.
docker cheat sheet

Things I wish I knew before I started using Docker

Commands

Init docker on mac os

boot2docker init

Restart docker vm on mac os

boot2docker up

Build new image from base dir

docker build -t hookio .

Run image you just built

docker run -p 49160:9999 hookio

Run same image in interactive mode

docker run -p 49160:9999 -i hookio

Curl running instance

curl $(boot2docker ip):49160

List all running containers

docker ps

Stop a container

docker stop <id>

Stop all containers

docker stop $(docker ps -a -q)

Delete all containers

docker rm $(docker ps -a -q)

Delete all images

docker rmi $(docker images -q)

Build docker-compose.yml file

docker-compose build

Start docker-compose.yml file

docker-compose up

Create bash shell to running instance by ID

docker exec -i -t 665b4a1e17b6 bash #by ID

Gotchas

  • virtual box gives the instance its own network ip ( probably in 192.168.*.* range )
  • knowing this ip address may be important to your application
  • if you crash the docker vm and restart, you'll have to re-export ENV variables ( read output of boot2docker up )
  • all configuration paths in your application should be based to __dirname ( if not already )
  • don't forget to run docker-compose build before docker-compose up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment