In this tutorial, we will learn some commands for managing the docker container.
Docker command syntax
$docker[option][command][arguments]
To list all the commands supported by docker, run
$docker
We will see the following results,
Attach Attach toarunning container
Build Build an image fromaDockerfile
Commit Createanewimage fromacontainer's changes
Cp Copy files/folders between a container and the local filesystem
Create Create a new container
Diff Inspect changes on a container'sfilesystem
Events Get real time events from the server
Exec Runacommand inarunning container
Export Exportacontainer'sfilesystem asatar archive
History show the history of an image
Images List images
Import Import the contents fromatarball tocreateafilesystem image
Info Display system-wide information
Inspect Returnlow-level information onacontainer orimage
Kill Killarunning container
Load Load an image fromatar archive orSTDIN
Login Log intoaDocker registry
Logout Log out fromaDocker registry
Logs Fetch the logs ofacontainer
Network Manage Docker networks
Pause Pause all processes withinacontainer
Port List port mappings oraspecific mapping for the CONTAINER
Ps List containers
Pull Pull an image orarepository fromaregistry
Push Push an image orarepository toaregistry
Rename Renameacontainer
Restart Restartacontainer
Rm Remove one ormore containers
Rmi Remove one ormore images
Run Runacommand inanewcontainer
Save Save one ormore images toatar archive
Search Search the Docker Hub forimages
Start Start one ormore stopped containers
Stats Displayalive stream of container(s)resource usage statistics
Stop Stoparunning container
Tag Tag an image intoarepository
Top Display the running processes ofacontainer
Unpause Unpause all processes withinacontainer
Update Update configuration of one ormore containers
Version Show the Docker version information
Volume Manage Docker volumes
Wait block untilacontainer stops, thenprint its exit code
To further see the options supported by a command, run:
$docker docker-subcommand info
The options supported by the docker subcommand are listed.
Test the connection to Docker Hub
By default, all images are pulled from the Docker Hub. We can upload or download an operating system image from Docker Hub. In order to check if we can upload/download images normally through Docker Hub, run
$docker run hello-world
The result should be:
Hello from Docker.
Thismessage shows that your installation appears tobe working correctly.
...
The output shows that you can access the Docker Hub and also download the docker image from the Docker Hub.
Search image
Search the container for the image, run
$docker search Ubuntu
We should get a list of available Ubuntu images. Remember, if you want an official image, check if the official column is [OK].
Download image
Once we have searched and found the image we want, we can run the following statement to download it:
$docker pull Ubuntu
To see all downloaded images, run:
$docker images
Running container
To run the container with the downloaded image, use the following command:
$docker run -it Ubuntu
Here, using -it will open a shell to interact with the container. Once the container is up and running, we can use it like a normal machine, and we can execute any command in the container.
Show all docker containers
To list all docker containers, run:
$docker ps
A list of containers is output, each container having a container id identifier.
Stop the docker container
To stop the docker container, run:
$docker stop container-id
Exit from the container
To exit from the container, execute:
$exit
Save container status
After the container is up and changed (such as installing an apache server), we can save the container state. This will save the newly created image on the local system.
Run the following statement to commit and save the container state:
$docker commit85475ef774repository/image_name
Here, the commit command saves the container state, 85475ef774, which is the container id of the container, and the repository, usually the username on the docker hub (or the newly added repository name) image_name, which is the name of the new image.
We can also add more information with -m and -a. With -m, we can leave a message saying that the apache server is already installed, and -a can add the author name.
like this:
Docker commit -m"apache server installed"-a"Dan Daniels"85475ef774daniels_dan/Cent_container
This is the end of our tutorial. This tutorial explains the important commands in Docker. If you have any questions, please leave a message.
Digital Timer Switch Sockets,Digital Timer Outlet,Plug-in Time Controller,Plug In Timers,Sockets with Timers
NINGBO COWELL ELECTRONICS & TECHNOLOGY CO., LTD , https://www.cowellsockets.com