Important Docker commands for Tom

Source: Internet
Author: User

Important Docker commands for Tom

In an earlier tutorial, we learned how to install Docker on RHEL CentOS 7 and create a docker container. In this tutorial, we will learn other commands for managing docker containers.

Docker command syntax
  1. $ docker [option][command][arguments]

To list all commands supported by docker, run

  1. $ docker

The following results are displayed,

  1. attach Attach to a running container
  2. build Build an image from a Dockerfile
  3. commit Create a new image from a container's changes
  4. cp Copy files/folders between a container and the local filesystem
  5. create Create a new container
  6. diff Inspect changes on a container's filesystem
  7. events Get real time events from the server
  8. execRun a command in a running container
  9. exportExport a container's filesystem as a tar archive
  10. history Show the history of an image
  11. images List images
  12. import Import the contents from a tarball to create a filesystem image
  13. info Display system-wide information
  14. inspect Return low-level information on a container or image
  15. kill Kill a running container
  16. load Load an image from a tar archive or STDIN
  17. login Log in to a Docker registry
  18. logout Log out from a Docker registry
  19. logs Fetch the logs of a container
  20. network Manage Docker networks
  21. pause Pause all processes within a container
  22. port List port mappings or a specific mapping for the CONTAINER
  23. ps List containers
  24. pull Pull an image or a repository from a registry
  25. push Push an image or a repository to a registry
  26. rename Rename a container
  27. restart Restart a container
  28. rm Remove one or more containers
  29. rmi Remove one or more images
  30. run Run a command in a new container
  31. save Save one or more images to a tar archive
  32. search Search the Docker Hub for images
  33. start Start one or more stopped containers
  34. stats Display a live stream of container(s) resource usage statistics
  35. stop Stop a running container
  36. tag Tag an image into a repository
  37. top Display the running processes of a container
  38. unpause Unpause all processes within a container
  39. update Update configuration of one or more containers
  40. version Show the Docker version information
  41. volume Manage Docker volumes
  42. wait Block until a container stops, then print its exit code

To further view the options supported by a command, run:

  1. $ docker docker-subcommand info

The options supported by the docker sub-command are listed.

 

Test the connection with Docker Hub

By default, all images are pulled from Docker Hub. You can upload or download an operating system image from Docker Hub. To check whether we can normally upload/download images through Docker Hub, run

  1. $ docker run hello-world

The result should be:

  1. HellofromDocker.
  2. This message shows that your installation appears to be working correctly.

The output indicates that you can access Docker Hub and download Docker images from docker Hub.

 

Search for images

Search for the container image and run

  1. $ docker search Ubuntu

We should get a list of available Ubuntu images. Remember, if you want an official image, please checkofficialWhether this column is[OK].

 

Download Image

Once the desired image is found, run the following statement to download it:

  1. $ docker pull Ubuntu

To view all downloaded images, run:

  1. $ docker images

 

Run containers

Run the following command to run the container by using the downloaded image:

  1. $ docker run -it Ubuntu

Here, use-itOpens a shell to interact with the container. After the container starts and runs, we can use it like a normal machine. We can execute any command in the container.

 

Show all docker containers

To list all docker containers, run:

  1. $ docker ps

A container list is output. Each container has a container id.

 

Stop a docker container

To stop the docker container, run:

  1. $ docker stop container-id

 

Exit from Container

To exit from the container, run:

  1. $ exit

 

Save container status

After the container is run and changed (for example, the apache server is installed), we can save the container status. This saves the newly created image on the local system.

Run the following statement to submit and save the container status:

  1. $ docker commit 85475ef774 repository/image_name

Here,commitThe command will save the container status,85475ef774Is the container id of the container,repository, Usually the user name on the docker hub (or the newly added repository name)image_nameIs the name of the new image.

We can also use-mAnd-aTo add more information. Pass-mWe can leave a message saying that the apache server has been installed, and-aYou can add the author name.

Like this:

  1. docker commit -m "apache server installed"-a "Dan Daniels"85475ef774 daniels_dan/Cent_container

Our tutorial is over now. This tutorial describes the important commands in Docker. If you have any questions, please leave a message.

For more Docker tutorials, see the following:

Docker installation application (CentOS 6.5_x64)

Configure Docker on Ubuntu 16.04 Server

Install Docker in Ubuntu 15.04

Docker installation instance

Create a basic image using Docker

How to install Docker on Ubuntu 15.04 and its basic usage

Docker usage notes on Ubuntu 16.04

Use Docker to start common applications in minutes

Solution for changing the configuration file of Docker in Ubuntu 16.04 does not take effect

Docker details: click here
Docker: click here

Via: http://linuxtechlab.com/important-docker-commands-beginners/

Author: Shusain Translator: lujun9972 Proofreader: wxy

This article was originally compiled by LCTT and launched with the honor of Linux in China

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.