Executing Basic Docker Commands

In this blog post we will see some of the basic docker commands to interact with containers and images.

[What is Docker? Containers and its Architecture. Learn more!]

Creating and running a container from an image

$ docker run <image_name>

$ docker run hello-world

$ docker run <image_name> <command>

$ docker run busybox echo hello there , $ docker run busybox ls
‘ls’ command prints folders inside of container

List all running containers

$ docker ps, docker ps –all

docker ps command lists the current running containers and docker ps –all lists all containers used till now

One of the common uses of docker ps is not only to check what is running but also to find the ID of the run container!

Restarting Stopped Containers

$ docker start -a <ContainerID>

find container ID by running $docker ps –all
$ docker start -a <ContainerID>

Removing Stopped Containers

$ docker system prune

this command will remove all the stopped containers

Get logs from the Container

$ docker logs <container id>

It shows logs of the container. Show two outputs because we ran it two time before the same container.

Stopping a Container – in two ways

$ docker stop <container id>

stops the container after ending other process inside of the container

$ docker kill <container id>

immediately stops the container without any wait

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s