Docker most simple entry of the (two) - Simple to use Docker

0. Introduction


  This chapter to write some how use Docker, pull common operations Docker's image and create the container and the like. Before you start writing, you need to understand what the meaning of a few nouns

  1. Mirroring: Mirroring is something of a similar installation package, try a variety of rain forest the wind, garden tomato, cabbage, etc., etc. win7 win7 mirror installed computer systems students should know that, in fact, plainly, is to install a system file. In the docker is also such a thing, we need to download the image warehouse

  2. Container: a container by means of the operating environment constructed image. For example, I installed through win7.gho rain forest the wind win7 system is good, and now win7 system is a container.

  3. Mirror Warehouse: a specialized storage site mirroring. docker's official repository mirroring is: https://hub.docker.com/ , because of slow access speed, so the domestic general use Ali cloud Netease warehouse or the like.

1. pull, view, delete mirror


 1.1 pull mirroring


   In docker pulls the mirror command is

docker pull [image name]

  For example, I want to pull a redis image, open the control terminal (windows or powershell cmd command may be used) enter the following command

docker pull redis

  My son to powershell example, enter docker pull redis, and then press Enter (PS: If you're in the country, it is best to configure mirroring source country, or download speeds touching, if not configured, see my first article " Docker Getting Started series - (a) For the configuration of Docker ").

  

  After Qiaowan enter, will become a docker will automatically download to download redis on mirror sites, explain here, if you need to specify the mirror version, simply append @ [version number can] behind the mirror, if not added, The default is the latest version. To redis as an example, I want to use redis1.0.1 version will enter this command

docker pull redis@1.0.1

  After the download is complete, it will become so. Description We have redis mirror pulled to the local

 

1.2 View Mirror


  View mirror command docker is

docker image ls

 

     Command will list the name of your current mirrors are pulled, I pulled up here a total of redis, mongo, mysql, ubuntu four mirror. Back to the preface of speaking, the mirror is equivalent to the installation package, I am here to download the equivalent of a good redis such as the installation package.

1.3 Remove Mirror


     In order to remove the mirror is docker

Image Docker RM [Mirror Mirror name or ID]

  We can remove a mirror with the name or ID by image rm, this ID is the value of IMAGE_ID we docker image ls listed, when we run into the same image name, we can confirm the deletion by a unique ID which mirrors. Try to remove the mirror redis

docker image rm redis

  The figure represents the deleted successfully

2. Create a container


  Container is built on top of a mirror if the mirror metaphor installation package, the container is your successful installation of the software, take micro-channel, for example child, you download an Android installation package in the micro-channel official website, the micro-channel installation package is mirrored, then you install on your mobile phone red rice is successful, micro letter icon is displayed, then you can use this micro-channel software. The micro-channel software is build out of the container. If you by some odd wicked craft skills, let your red rice phone can install two or more micro-channel and at the same time there is, then that is you build a lot of container

  2.1 Create Container


  You can create a container using the following command:

docker run -d -p [Host Port Number]: [Container Port Number] --name [Custom Title] [image name]

  Parameters explanation:

  docker run: represents the creation or operation of a vessel

  -d: representation uses a background process (that is, without blocking the current process)

  -p:表示指定端口号

  [主机端口号]:表示安装docker的那台机子通过哪个端口与容器通信

  [容器端口号]:表示创建的容器通过哪个端口与主机通信

  --name [自定义名称]:表示给你创建的容器取个名字

  [镜像名称]:不用多说,就是我们拉取下来的镜像

  我们尝试运行一下redis,输入以下命令(首先确保你的redis这个镜像存在)

docker run -d -p 6379:6379 --name redis01 redis

   运行结果如下,会返回一个64位长度的字符串,这个就是容器的id,也是唯一的。

  

 

   2.2 查看运行的容器


  运行完容器之后,怎么看启动成功了,通过以下命令

docker ps

  

  可以看到status那一栏显示Up状态,则代表成功了。现在我们通过软件连接一下,看下redis服务器是否能够正常运行

  图上可以看到,我们已经成功运行了redis容器

  2.3 停止和删除容器


  运行完容器,怎么停止和删除呢,通过以下命令(要先停止才能删除容器

  停止:

docker stop [容器名称]

  删除:

docker rm [容器名称]

  参数解释:

  [容器名称]:你可以使用--name 参数后面自己定义的名字,或者使用返回给你的64位字符长度的ID

  停止redis容器,会返回redis容器的名字

 

   删除redis容器,也会返回redis容器的名字

  

 3. 总结


  本章主要讲了镜像和容器的关系。

Guess you like

Origin www.cnblogs.com/lihuadeblog/p/11324025.html