Unlocking the Power of Docker | A Quick Guide 🚀 🐳

Dinuka Kasun Medis
4 min readFeb 6, 2024

Hello, I have decided to digitally preserve an old Docker note of mine 🐳. I am looking forward to writing an updated version soon and until that I hope this can be of assistance to someone like you.🤠

⚠️ Warning: Reading this blog may turn you into a Docker enthusiast. Brace yourself for the containerization bug — it’s contagious! 🐳✨

Concept AI art for DOCKER | Generated using BARD AI

🐳 Docker is a container in a computer, like computer in a computer.

Generated using BARD AI

🐳 Docker Vs Virtual Machine

Docker Vs VM

🐳 Image — Container

🐳 Image

  • Image is a read only template that contains a set of instructions to create a container.

🐳 Container

  • Container is a runnable interface of image
  • Isolated environment.
  • Separate from main O/S
  • Like a little server run on your computer 😁

🐳 Docker version

  • There are two versions for client and server.
  • When we download Docker two things come 🤯. Docker Server (Daemon 👹) and Docker CLI.

🐳 Docker Server (Daemon 👹)

This runs background process, create images and run containers.(Basically Docker running on your computer.)

🐳 Docker CLI

Command line tool that we use to interact with the Docker server.

🐳 Run hello-world image in a new container

> docker run hello-world ↲

When we run the command that we sent to the doctor server and ask do you have this hello-world image? Then notify to the CLI and Demon check that image available on Docker hub. If “hello-world” exist in the hub then download that and create a new container using image instructions, then send a log to the CLI.

When once downloaded that image, then it cached in the docker demon and when we later run that again, we will receive a quick response.

> docker run hello-world ↲
> docker container run hello-world ↲

Both above commands are support, but second one with contest (“container”) is recommended.

🐳 Default commands

> docker container run busybox ↲
  • busybox” → Simple image of a super light weight Unix server.
> docker container run busybox ls ↲
  • Here, “ls” is default command. This will only show your running container. To see all, “ls -a”
> docker container run busybox ls -a ↲
> docker container run busybox echo "beacon" ↲
CONTAINERID IMAGE COMMAND CREATED STATUS PORTS NAMES
  • CONTAINERID → Unique ID (short 256 hash).
  • IMAGE → Image name.
  • COMMAND → Default command that run whenever you created this container.
  • CREATED → Container created date and time.
  • STATUS → Statues of the container. (Ex: created)
  • PORTS → List of ports map to the host.
  • NAMES → Names assigned to that container. We can give a name or Docker will give a random name for the container.
  • “run” command → create + start
> docker container create hellow-world ↲
  • Return id of the created container.
> docker container start -a <container-id> ↲
  • “-a” flag attaches the output of this container which is going to be the contest displayed from this “ls” command and write in the terminal. Now status of the container is “Exited” because that container run and the only job is print something and exit. So, it is a simple program and have a simple life cycle.
> docker system prune --all ↲
  • Remove all unused images, not just dangling ones. Dangling image is just one that is not tagged and is not referenced by another container.
> docker container create bysybox ls ↲
> 037........ (container id prints)

> docker container run <container id> ↲
> 037........ (container id prints)

> docker container logs <container id> ↲
bin
dev
.
.
.
.
user
var
> docker container create busybox ping google.com ↲

> docker container start <container id> ↲ (Now status is "UP")

> docker container stop <container id> ↲

Docker gives 10 seconds to stop process before you stop that, if some process happening in that container. Then run kill command.

> docker conatiner kill <container id> ↲

🐳 Remove container.

> docker containre rm <container id> ↲

> docker container rm -f <container id> ↲

🐳 Inspect Container.

> docker container inspect <container id> ↲

This will return a json and contains many details of the container.

🐳 Run commands in already running container

> docker container run redis ↲

This will keep container running and open a new tab in terminal.

> docker container exec -it <container id> redis-cli ↲
  • Without “-it” program will not return. And it helps to interact with the container files.
  • “redis-cli” → programe name that we wants to run on this container.
> exit ↲
  • “exit” to exit 🦶
> docker container exec -it <container id> sh ↲
  • With “sh” command you can open any container with command prompt.
  • Like “sh”, you can use “cd”, “ls” ……
> That's all for today😵‍💫🐳 ↲

Stay tuned for the next article on creating a Docker image. Until then, ciao👏👋.

PS: If you notice anything that needs updating, please remember to leave a comment ✍️

--

--

Dinuka Kasun Medis

Hej, jag heter Dinuka Kasun. Välkommen till min profil. Arbeta som mjukvaruingenjör. Och nu för tiden lär jag mig svenska. 🤓🇱🇰 🇸🇪