Skip to content

Instantly share code, notes, and snippets.

@dinolupo
Last active August 29, 2015 14:21
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 dinolupo/12c62979610cf6c16ea1 to your computer and use it in GitHub Desktop.
Save dinolupo/12c62979610cf6c16ea1 to your computer and use it in GitHub Desktop.
Docker frequent commands

Docker frequent commands

running a container

docker run -d -P  training/webapp python app.py
-d //is for background
-P // map any port inside container to the our host
docker ps -l  // details of last container
docker ps -a  // details of all containers (also stopped ones)

map ports explicitly

docker run -d -p 5000:5000 <container_image> <command>

how to retrieve ip/ports of a docker container and boot2docker VM

// from boot2docker CMD you can run
boot2docker ip 
// to retrieve IP of the boot2docker VM

docker port <ID or NAME> <PORT> //show mappings

example on smart method to retrieve ip of a docker running image, in this example an apache2 image and curl command to call that

docker build -f apache-dockerfile-ex3 -t apache-ex3 .
cid=$(docker run -itd -P apache-ex3)
nid=$(docker inspect --format '{{.NetworkSettings.IPAddress}}' $cid)
curl $nid

other commands

docker images // show current images
docker kill $(docker ps -q) // kill all running docker containers
docker rm $(docker ps -aq) // remove all containers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment