Docker container handbook

# Introduction

You will be learning about container manipulation basics in detail. Container manipulation you will be performing every single day. You can visit the official refer here for the Docker command-Line. Now, We write a Docker container handbook.

Run a Container

The syntax of this command is below for version 1.13:

docker run <image name>

In the new version, The syntax of this command is 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 is as follows:

docker container run <image name>

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

For example, To run a container using the image as my terminal below:

docker container run --publish 8080:80 nginx

Publish a Port

The 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 the background, you can use the –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

  • CONTAINER ID
  • 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 the command “docker container ls –all

The syntax removes Dangling Containers

docker container rm <container identifier>

Execute Commands Inside a Container

docker run name-of-image uname -a

Docker container handbook. I hope will this your helpful. Thank you for reading the DevopsRoles page!

,

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 DevopsRoles.com 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 *

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