Docker study notes

Docker is an open source engine that can automatically deploy developed applications to containers. Written by the Docker team and released under the Apache2.0 open source license.

Docker components

  • Docker client and server;
  • Docker image;
  • Docker container;
  • Registry。

Docker installation

Download address: https://download.docker.com/mac/stable/Docker.dmg

Then install the graphical interface prompts to install step by step.

Docker use

Check the versions of Docker Engine , Docker Compose and Docker Machine

$ docker --version
Docker version 1.13.0, build 49bf474

$ docker-compose --version
docker-compose version 1.10.0, build 4bd6f1a

$ docker-machine --version
docker-machine version 0.9.0, build 15fd4c7

Note . The above is just an example, your output will vary depending on your version


Browse applications and run a case

Open a command line terminal and use the Docker command to check that Docker is not working as expected. You can use these commands docker version , docker ps and docker run hello-world to confirm that Docker is running normally. If these commands are executed normally, then Docker is said to be running.

For a more exciting approach, run a Dockerized web server, but of course you must have the image you want to run locally.

docker run -d -p 80:80 --name webserver nginx


If the image is not found locally, Docker will pull the image from Docker Hub.

  • Execute while your web server is running to docker psview the details of the web server container.
  • Stop or remove the container and mirror 
    the nginx web server will continue to run until you stop or remove the container, if you want to stop the web server: docker stop webserver, start the server with the command docker start webserver. To see if a container is stopped with the command docker ps;  to docker ps -asee the terminated status of a container. Use the docker rm -f webservercommand to remove a running container. This command removes the container, but not the nginximage. You can use the docker list command to list local images. You might save some images locally so that you don't have to go to Docker Hub to pull the images again. To remove an image that is not needed for a long time, use docker rmi followed by the ID number and image name. For example, docker rmi ngix.

  • Command summary:

docker ps View running containers

docker stopStop a running container

docker startstart the container

docker ps -aView terminated containers

docker rm -f webservercommand to remove a running container

docker list List local mirrors

docker rmi deleted image

Other common commands

docker pull // Download the image from the network


The docker create command adds a read-write layer to the specified image ( image ), forming a new container. Note that this container is not running.


The Docker start command creates a process isolation space for the container filesystem. Note that each container can only have one process isolation space.


The docker ps command will list all running containers. This hides the existence of non-running containers, if we want to find these containers, we need to use the following command.


The docker ps -a command will list all containers, whether they are running or stopped.


docker images命令会列出了所有顶层(top-level)镜像。实际上,在这里我们没有办法区分一个镜像和一个只读层,所以我们提出了top-level镜像。只有创建容器时使用的镜像或者是直接pull下来的镜像能被称为顶层(top-level)镜像,并且每一个顶层镜像下面都隐藏了多个镜像层。


docker images –a命令列出了所有的镜像,也可以说是列出了所有的可读层。如果你想要查看某一个image-id下的所有层,可以使用docker history来查看。


docker stop命令会向运行中的容器发送一个SIGTERM的信号,然后停止所有的进程。


docker kill 命令向所有运行在容器中的进程发送了一个不友好的SIGKILL信号。


docker stopdocker kill命令会发送UNIX的信号给运行中的进程,docker pause命令则不一样,它利用了cgroups的特性将运行中的进程空间暂停。


docker rm命令会移除构成容器的可读写层。注意,这个命令只能对非运行态容器执行。


docker rmi 命令会移除构成镜像的一个只读层。你只能够使用docker rmi来移除最顶层(top level layer)(也可以说是镜像),你也可以使用-f参数来强制删除中间的只读层。 


docker commit命令将容器的可读写层转换为一个只读层,这样就把一个容器转换成了不可变的镜像。


docker build命令非常有趣,它会反复的执行多个命令。build命令根据Dockerfile文件中的FROM指令获取到镜像,然后重复地1runcreatestart)、2)修改、3commit。在循环中的每一步都会生成一个新的层,因此许多新的层会被创建。


docker exec 命令会在运行中的容器执行一个新进程。



docker inspect命令会提取出容器或者镜像最顶层的元数据。


docker save命令会创建一个镜像的压缩文件,这个文件能够在另外一个主机的Docker上使用。和export命令不同,这个命令为每一个层都保存了它们的元数据。这个命令只能对镜像生效。


docker export命令创建一个tar文件,并且移除了元数据和不必要的层,将多个层整合成了一个层,只保存了当前统一视角看到的内容(译者注:expoxt后的容器再importDocker中,通过docker images –tree命令只能看到一个镜像;而save后的镜像则不同,它能够看到这个镜像的历史镜像)。


docker history命令递归地输出指定镜像的历史镜像。


转注:

http://dockone.io/article/783

https://blog.csdn.net/jiang_xinxing/article/details/58025417

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325933751&siteId=291194637