Docker Getting Started Tutorial (2) Command
[Editor's Note] DockerOne has translated Flux7's Docker introductory tutorial. This article is the second in a series of introductory tutorials. It introduces the basic commands of Docker and the usage and functions of the commands.
In the first article of the Docker tutorial series, we learned the basics of Docker, how it works and how to install it. In this post, we'll learn 15 Docker commands and learn how it works by doing it.
First, let's check if Docker is installed correctly by running the following command:
if this command is not found, then Docker is not installed correctly. If installed correctly it will output something like the following:
In the first article of the Docker tutorial series, we learned the basics of Docker, how it works and how to install it. In this post, we'll learn 15 Docker commands and learn how it works by doing it.
First, let's check if Docker is installed correctly by running the following command:
docker info
if this command is not found, then Docker is not installed correctly. If installed correctly it will output something like the following:
![](http://dl2.iteye.com/upload/attachment/0105/0966/bf99f48d-7bd7-3e7d-bb2d-73b441c956f9.png)
At this point there are no images or containers in Docker. So, let's pull a pre-built image with the command:
sudo docker pull busybox
![](http://dl2.iteye.com/upload/attachment/0105/0968/e44e3ab0-0c05-3529-a243-07650aba8d30.png)
Next we'll run a Hello World example, let's call it "Hello Docker" for now.
docker run busybox /bin/echo Hello Docker
![](http://dl2.iteye.com/upload/attachment/0105/0972/63ef61cd-b819-334f-acf4-430f5f497cf7.png)
hello docker
:
sample_job=$(docker run -d busybox /bin/sh -c "while true; do echo Docker; sleep 1; done")
![](http://dl2.iteye.com/upload/attachment/0105/0980/87a68673-bf9c-3a23-a1af-1d1f29aa3833.png)
sample_job
The command will print Docker every second, you can use
Docker logs
it to view the output. If there is no name, the job will be assigned an id, and it
Docker logs
will become more troublesome to use commands such as viewing logs later.
Run
Docker logs
the command to see the current status of the job:
docker logs $sample_job
All Docker commands can be viewed with: The container
docker help
named
sample_job
, can be stopped with:
docker stop $sample_job
Restart the container with the following command:
docker restart $sample_job
If you want to remove the container completely, you need to stop the container , then it can be removed. Like this: to save the state of the container as an image, use the command: Note that the image name can only take characters [az] and numbers [0-9]. You can now view a list of all images with the following command: In our previous Docker tutorial , we learned that images are stored in the Docker registry. The image in the registry can be found with the following command: To view the historical version of the image, execute the following command: Finally, use the following command to push the image to the registry: You must know if the repository name is the root repository, it should use this format . These are all very basic Docker commands. In Chapter 6 of our Docker tutorial series , we'll discuss how to use Docker to run Python web applications, as well as some advanced Docker commands.
docker stop $sample_job docker rm $sample_job
docker commit $sample_job job1
docker images
docker search (image-name)
docker history (image_name)
docker push (image_name)
(user)/(repo_name)