The MOST EVER usefullest Docker commands (as determined by some guy on the internet)

0

Full article

After taking my first look at Docker and then playing around with building images, I've now progressed into other proprietary work stuff, so... won't be sharing that on here. I like having a job.

That being said, I'll just make note of any useful commands I come across this week. As much for me as you!

Creation

  • Create an image from a Dockerfile: docker build .
  • Create a container from an image (run in bkgd): docker run -d <image hash>
  • Interact with running container: docker exec -it <container hash> bash
  • Create a container and interact with it: docker run -it <image hash>

The exec command is great. It allows you execute a command inside a running, such as using some tool only available in the container to export some settings, which you can dump in a directory that's being shared with the -v flag, so that you can import it into future containers. Handy stuff.

Status

  • View images: docker images
  • View containers: docker ps or docker container ls
  • View all containers (including stopped ones): docker ps -a

Removal

(Layers of) images are the blueprint for the application you'd like to run, while containers are an instance of an image. You can spin up multiple containers for a given image, and each container is separate.

Containers

  • Stop all containers: docker stop $(docker ps -a -q)
  • Remove stopped containers: docker rm $(docker ps -a -q)
  • Kill all containers (even running ones): docker rm -f $(docker ps -a -q)

Images

  • Remove image (unless a container or another image exists that's based off it): docker rmi $(docker images -q)
  • Force removal: docker rmi -f $(docker images -q)

Author

Grant Winney

Is there anything more satisfying than sharing knowledge? Of teaching someone and witnessing their "ah ha" moment? I usually write about tech, but no promises. I hope you find something interesting!



Comments