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
$ docker [option][command][arguments]
To list all commands supported by docker, run
$ docker
The following results are displayed,
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes on a container's filesystem
events Get real time events from the server
execRun a command in a running container
exportExport a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on a container or image
kill Kill a running container
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
network Manage Docker networks
pause Pause all processes within a container
port List port mappings or a specific mapping for the CONTAINER
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart a container
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop a running container
tag Tag an image into a repository
top Display the running processes of a container
unpause Unpause all processes within a container
update Update configuration of one or more containers
version Show the Docker version information
volume Manage Docker volumes
wait Block until a container stops, then print its exit code
To further view the options supported by a command, run:
$ 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
$ docker run hello-world
The result should be:
HellofromDocker.
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
$ 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:
$ docker pull Ubuntu
To view all downloaded images, run:
$ docker images
Run containers
Run the following command to run the container by using the downloaded image:
$ 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:
$ docker ps
A container list is output. Each container has a container id.
Stop a docker container
To stop the docker container, run:
$ docker stop container-id
Exit from Container
To exit from the container, run:
$ 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:
$ 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:
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