Docker container handbook

# Introduction

You will be learning about container manipulation basics to detail. Container manipulation you will performing every single day.
You can visit the official refer here for the Docker command-Line.

Run a Container

The syntax this command as below for version 1.13:

docker run <image name>

New version, The syntax this command as below:

docker <object> <command> <options>

In this syntax:

  • object can be a container, image, network or volume object.
  • command is the run command.
  • options can be any valid parameter that can override the default behavior of the command. example, –publish option for port mapping.

Now, for this syntax, the run command as follows:

docker container run <image name>

The “image name” can any image from an online registry or your local system.

Example, To run a container using image as my terminal below:

docker container run --publish 8080:80 nginx

Publish a Port

Host system doesn’t know inside a container. How to outside access inside a container. The syntax, The Publish a port a container.

--publish <host port>:<container port>

Use Detached Mode

To a container running in backgroup, you can use –detach option with the run command

docker container run --detach --publish 8080:80 nginx

List Containers

You will list out containers that are currently running.

docker container ls

List all out containers.

docker container ls --all

Stop or Kill a Running Container

The syntax Stop or kill a Container

docker container stop <container identifier>
docker container kill <container identifier>
  • <container identifier>: can either be the id or the name of the container.

How to restart a Container

Restarting a container that has been previously stopped or killed

docker container start <container identifier>

Rebooting a running container.

docker container restart <container identifier>

Rename a Container

By default, every container has two identifiers

  • NAME

Using the –name option defined Naming a container

docker container run --detach --publish 8888:80 --name nginx-container nginx

The syntax rename a container

docker container rename <container identifier> <new name>

Remove Dangling Containers

Find out containers are not running, use command “docker container ls –all

The syntax remove Dangling Containers

docker container rm <container identifier>

Execute Commands Inside a Container

docker run name-of-image uname -a


About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.