Common Docker Commands

     We know that Docker is a software framework for building, running, and managing containers on servers and the cloud. Docker gives you the best of this because you can run your tests in containers or isolate them in development and deployment. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.

     In Docker, all software parts can be organized in containers. This includes the operating system, software, dependencies, environment variables, etc. Containers can be shared among different users, enabling quick installation and running of software and services. This makes Docker handy for automation testing, as the relevant container can just be downloaded and run as part of the automated test. However, Docker is also secure because it runs as an isolated process on the host machine. In this article, I would like to share the common Docker commands. The commands categorized as:

  • Lifecycle Commands.
  • Start and Stop Containers Commands.
  • Docker Image Commands.
  • Docker Container and Image Information Commands.
  • Network Commands.
Lifecycle Commands

Below we will discuss various lifecycle commands that using regularly,

To create a container without starting it:

docker create [IMAGE]

Rename an existing container:

docker rename [CONTAINER_NAME] [NEW_CONTAINER_NAME]

Run a command in a new container:

docker run [IMAGE] [COMMAND]

Remove container after it exits:

docker run –rm [IMAGE]

Start a container and keep it running:

docker run -td [IMAGE]

Start a container and creates an interactive bash shell in the container:

docker run -it [IMAGE]

Create, Start, and run a command inside the container and remove the container after executing command:

docker run -it-rm [IMAGE]

Execute command inside already running container:

docker exec -it [container]

Delete a container (if it is not running):

docker rm [CONTAINER]

Update the configuration of the container:

docker update [CONTAINER]

Start and Stop Containers Commands

Below we will discuss various start and stop containers commands,

Start container:

docker start [CONTAINER]

Stop running container:

docker stop [CONTAINER]

Restart container:

docker restart [CONTAINER]

Pause processes in a running container:

docker pause [CONTAINER]

Unpause processes in a running container:

docker unpause [CONTAINER]

Block a container until others stop:

docker wait [CONTAINER]

Kill a running container:

docker kill [CONTAINER]

Attach local standard input, output, and error streams to a running container:

docker attach [CONTAINER]

Docker Image Commands

Below we will discuss various commands that operate with Docker image,

Create an image from a Dockerfile:

docker build [URL/FILE]

Create an image from a Dockerfile with Tags:

docker build -t [URL/FILE]

Pull an image from a registry:

docker pull [IMAGE]

Push an image to a registry:

docker push [IMAGE]

Create an image from a tarball:

docker import [URL/FILE]

Create an image from a container:

docker commit [CONTAINER] [NEW_IMAGE_NAME]

Remove an image:

docker rmi [IMAGE]

Load an image from a tar archive or stdin:

docker load [TAR_FILE/STDIN_FILE]

Save an image to a tar archive:

docker save [IMAGE] > [TAR_FILE]

Docker Container and Image Information Commands

Below we will discuss various commands to deal with Container and Image information,

List running containers:

docker ps

Lists both running containers and ones that have stopped:

docker ps -a

List the logs from a running container:

docker logs [CONTAINER]

List low-level information on Docker objects:

docker inspect [OBJECT_NAME/ID]

List real-time events from a container:

docker events [CONTAINER]

Show port mapping for a container:

docker port [CONTAINER]

Show running processes in a container:

docker top [CONTAINER]

Show live resource usage statistics of container:

docker stats [CONTAINER]

Show changes to files (or directories) on a file system:

docker diff [CONTAINER]

List all images that are locally stored with the docker engine:

docker [image] ls

Show the history of an image:

docker history [IMAGE]

Network Commands

Below we will discuss various network commands to work with Docker,

List networks:

docker network ls

Remove one or more networks:

docker network rm [NETWORK]

Show information on one or more networks:

docker network inspect [NETWORK]

Connects a container to a network:

docker network connect [NETWORK] [CONTAINER]

Disconnect a container from a network:

docker network disconnect [NETWORK] [CONTAINER]

     Thanks for referring this long article. I hope all the commands are useful and helpful in your Docker management cycle and configurations.

make it perfect!

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