Skip to content

Instantly share code, notes, and snippets.

@roujdami
Last active April 26, 2020 04:13
Show Gist options
  • Save roujdami/a514f2a72a498dc940d006b3aef1ff19 to your computer and use it in GitHub Desktop.
Save roujdami/a514f2a72a498dc940d006b3aef1ff19 to your computer and use it in GitHub Desktop.

Basics

docker ps                      // Show running docker containers 
docker ps -a                   // Show all containers, both stopped and running
docker ps -n x                 // Shows the last x containers, running or stopped, ex: docker ps -n 5)
docker ps -l

docker images

docker rm container_id   
docker rm $(docker ps -a -q)   // delete all containers

docker rmi <image_id>          // delete an image
docker rmi $(docker images -q) // delete all images

docker start <container_id>    // (ex: docker start aa3f365f0f4e)
docker start <container_name>  // (ex: docker start rails_dev_container)
 
docker attach <container_id>   // (ex: docker attach aa3f365f0f4e)
docker attach <container_name> // (ex: docker attach rails_dev_container)

To see what's happening inside the container

 

docker logs container_name     //
docker logs -f container_name  // (like the tail -f)
docker logs -ft container_name // (prefix log entries with timestamps)
docker logs --tail 10 daemon_container  (get the last 10 lines of the log)
docker logs --tail 0 -f daemon_container (follow the logs without having to read the whole log file)

Inspecting the container's processes

 

docker top daemon_container

Running a process inside a container

Background

docker exec -d daemon_container touch /etc/new_config_file

Interactive

docker exec -t -i daemon_container /bin/bash 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment