Docker Rest(Remote) API

来源:互联网 发布:软件测试原则包括 编辑:程序博客网 时间:2024/06/13 13:48

本人是基于工作的需求,对docker稍微做了一些了解,如果不正确的地方,还请大家多多吐槽!!!

What happens when you run a container?

Either by using the docker binary or via the API, the Docker client tells the Docker daemon to run a container.

$ docker run -i -t ubuntu /bin/bash

So what happens under the hood when we run this command?

In order, Docker Engine does the following:

  • Pulls the ubuntu image: Docker Engine checks for the presence of the ubuntuimage. If the image already exists, then Docker Engine uses it for the new container. If it doesn’t exist locally on the host, then Docker Engine pulls it from Docker Hub.
  • Creates a new container: Once Docker Engine has the image, it uses it to create a container.
  • Allocates a filesystem and mounts a read-write layer: The container is created in the file system and a read-write layer is added to the image.
  • Allocates a network / bridge interface: Creates a network interface that allows the Docker container to talk to the local host.
  • Sets up an IP address: Finds and attaches an available IP address from a pool.
  • Executes a process that you specify: Runs your application, and;
  • Captures and provides application output: Connects and logs standard input, outputs and errors for you to see how your application is running.

You now have a running container! Now you can manage your container, interact with your application and then, when finished, stop and remove your container.

docker--run for windows

Because the Docker daemon uses Linux-specific kernel features, you can’t run Docker natively in Windows. Instead, you must use docker-machine to create and attach to a Docker VM on your machine. This VM hosts Docker for you on your Windows system.

Run a Hello world

Let’s run a hello world container.

$ docker run ubuntu /bin/echo 'Hello world'Hello world

Run an interactive container

Let’s specify a new command to run in the container.

$ docker run -t -i ubuntu /bin/bashroot@af8bae53bdd3:/#

In this example:

  • docker run runs a container.
  • ubuntu is the image you would like to run.
  • -t flag assigns a pseudo-tty or terminal inside the new container.
  • -i flag allows you to make an interactive connection by grabbing the standard in (STDIN) of the container.
  • /bin/bash launches a Bash shell inside our container.

Listing images on the host

Let’s start with listing the images you have locally on our host. You can do this using the docker images command like so:

$ docker imagesREPOSITORY          TAG                 IMAGE ID            CREATED             SIZEubuntu              14.04               1d073211c498        3 days ago          187.9 MBbusybox             latest              2c5ac3f849df        5 days ago          1.113 MBtraining/webapp     latest              54bb4e8718e8        5 months ago        

So when you run a container you refer to a tagged image like so:

$ docker run -t -i ubuntu:14.04 /bin/bash
If you want to new Images

Getting a new image

So how do you get new images? Well Docker will automatically download any image you use that isn’t already present on the Docker host. But this can potentially add some time to the launch of a container. If you want to pre-load an image you can download it using the docker pull command. Suppose you’d like to download thecentos or ubuntu image.

$ docker pull centos (ubuntu)Pulling repository centosb7de3133ff98: Pulling dependent layers5cc9e91966f7: Pulling fs layer511136ea3c5a: Download completeef52fb1fe610: Download complete. . .Status: Downloaded newer image for centos

You can see that each layer of the image has been pulled down and now you can run a container from this image and you won’t have to wait to download the image.

$ docker run -t -i centos /bin/bashbash-4.1#

Pulling our image

You’ve identified a suitable image, training/sinatra, and now you can download it using the docker pull command.

$ docker pull training/sinatra

Updating and committing an image

To update an image you first need to create a container from the image you’d like to update.

$ docker run -t -i training/sinatra /bin/bashroot@0b2616b0e5a8:/这次就分享到这里,未完待续......

0 0
原创粉丝点击