Personal Docker Cheatsheet
December 14, 2020 - 1 min read
To test something on a specific Linux distro, I used to create a VM instance on the cloud or on my laptop. Instead, with Docker, you are one command away from any Linux distro you like:
docker run -it ubuntu
This will pull an Ubuntu image, create a container, and connect to it.
There are times I don’t need Docker that much, and with enough time gap, I keep forgetting the commands I need. To stop rereading the docs again and again, I listed some of the useful ones here:
See running containers | docker ps |
Get last ran container id | docker ps -ql |
Run a container with the default command | docker run -it debian |
Run a command in a new container | docker run -it node sh |
Create a new image from a container's changes | docker commit $(docker ps -lq) name:tag |
Build an image from a Dockerfile | docker build -t name:tag . |