Docker Commands to make your LIFE a BREEZE!

·

2 min read

Cover Image for Docker Commands to make your LIFE a BREEZE!

Often times as a developer, you need to wrap your code in an isolated environment, so that you can test it on someone else’s computer or deploy it on cloud.

That is when you need Docker.

In this article, you’ll find common commands you would need while testing and deploying applications.

Refer to this article as a quick reference guide for commands you'll need to look up regularly.

Build a docker container

docker build -t <image_name> .

Key thing to note here is that a docker container runs in isolation to the rest of the operating system it is built on, but, it does need the same architecture in the operating system as a base to be rebuilt on.

So, for example, if a docker container was built on the x86 architecture pc, it would need any computer with a variant of this architecture to rebuild it. It would not work on the AArch64 architecture in the macOS mX series.

You can also specify the operating system corresponding to how the image should be built:

docker build --platform=linux/amd64 -t <image_name> .

Running the docker container

docker run --name <container_name> <image_name>

In the above command, slt-container is the name of the docker container which contains the docker image slc-vnc-test.

Checking running containers

docker ps

Checking stopped containers or container ID or name

docker ps -a

Checking Logs using Container Name or ID

docker logs <container_name>

Stopping a Docker Container

docker stop <container_name>

Deleting a Docker Container

docker rm <container_name>

Remove Unnecessary Space occupied by the container (Cache) after deleting the Docker Container

docker system prune -a
docker builder prune --all

List Docker Images

docker images

Delete a Docker Image

docker rmi <image_name>

Remove all unused images

docker image prune

And that is it, you can now deploy your application which contains the DockerFile and your application code to any cloud provider.

Also, if you need more commands, feel free to refer to the official docker documentation here, or the CLI CheatSheet linked here.

Happy Deployment!

Until next time,

Shreyas