Basic Introduction and example of Docker

Source: Internet
Author: User
Tags docker ps

Basic Introduction and example of Docker

Docker has developed over the past few years. Particularly since the 2013 s, with the open source of an LXC-based advanced container engine, Docker has been well supported in both linux and windows, in addition, many companies have used docker in the actual production environment deployment. This article briefly introduces the following aspects:

1. Basic Introduction to docker

2. install and configure docker in windows

3. Basic commands

4. Use vs2017 for docker debugging

5. Package A. net core site image

1. Basic Introduction to docker

Many of my friends may have heard about docker and have not paid much attention to it. Here I will briefly introduce some of its basic knowledge. If you have any questions, please correct them!

1. Introduction to docker

Many people have a concept of preemptible. docker is a lightweight container. So here we will first popularize that docker itself is not a container, but an engine tool for managing containers. It contains a server and a client. The server is a service process that manages all containers and file systems. The client is a server controller used to control docker server processes. As for containers, it mainly refers to running instances of some specific applications. This ensures that the running environment of the current application is independent and that containers are independent of each other.

A product from development to launch, from the operating system, to the running environment, and then to the application configuration. As developers, we need to care about a lot of things. This is also a problem that many Internet companies have to deal with. Especially after iterations of various versions, the compatibility of different versions of the environment is a test for O & M personnel. Docker is developing so rapidly because it provides a standardized solution.

Docker provides a set of virtualization and file system support, allowing professionals to freely assemble the required runtime environment into containers, and provides isolation during container runtime. Just like a large tanker carrying containers, each container can be understood as our container. The contents of this container are completely customized by the assembler.

2. Basic concepts of docker

Docker itself is a container running carrier. To run a container, you must correctly understand the concepts of warehousing, image, and container. As described above, the meaning of the image is clear when you deploy a running instance of the container. An image is a packaged and deliverable running environment. when we need it, we can create a corresponding running instance through the docker client, that is, our container. As for warehousing, we put a pile of images in place. We can release the images to the warehouse and pull them from the warehouse as needed.

3. basic use of docker

Take the web as an example. After the development is complete, we can package the application into an image, publish it to our own storage server, or directly upload it to the server to pull or load the image, set the corresponding port ing and start the container. If we have multiple web containers, we can also use negix to load the proxy in front. I will use a. net core site for a simple example later. Of course, there are also many continuous integration solutions, such as automatically generating images after the code is submitted and deploying them. We will not introduce them here.

 

2. install and configure docker in windows

Here I will introduce how to install Docker in windows and related configuration information. Currently, Docker for Windows contains two engines by default: containers (linux and windows)

1. Download Docker for Windows, https://docs.docker.com/docker-for-windows/install/#download-docker-for-windows

2. check whether the Hyper-V function is enabled. If you cannot enable or disable the windows function, you do not need to worry about it, during the installation of docker, the system will also be checked. If not, the system will be added and started by default. However, you can directly perform this step while waiting for the download of docker. After Hyper-V is installed, you may need to restart the system.

3. After the installation is complete, you can view the Hyper-V manager. If the installation is normal, a linux virtual machine is created by default as follows:

 

We can also view the Docker version through PowerShell:

 

After the installation is successful, we can set it accordingly.

1. Right-click the whale icon (the online image I am looking for) and click Settings

 

2. The settings page is as follows. Shared Drives can set our corresponding ing drive disk to ensure that drive C is selected, and then select the drive letter where your application is located. In the Advanced option, you can set the CPU corresponding to docker to occupy resources in memory. Netword is the current Docker IP address. Proxies can be used to set the corresponding proxy information. Daemon mainly sets the corresponding warehouse and the corresponding warehouse image site (separated from the docker image, this is the image corresponding to the warehouse, because the access to foreign sites is too slow, you can set up an image proxy site in China ).

 

It is particularly emphasized that, because it is too slow to pull images from the Docker official website, please purchase the VPN service on your own, or find the storage agent site. Netease And DaoCloud in China have corresponding free accelerators, here is my settings:

  

3. As mentioned above, Docker for Windows provides two engines, which can be switched by right-clicking the Switch to Windows Containers function.

4. At the same time, Docker for Windows provides container interface management tools. You can right-click the Kitematic function in the menu to enter. The first time you may be prompted to download and install the tool, the interface is as follows:

 

Iii. Docker basic commands

After the setup is complete, we can use the following command to operate docker. Here I mainly perform this operation in PowerShell, or through command line cmd.

1. docker pull: drag an image from the Repository

2. docker run: run the container. If the image of the container to be run does not exist, it is automatically pulled. For example, docker run hello-world

3. docker stop: stop container running
4. docker start: start container running
5. docker commit: Submit the container to the image
6. docker images: view the current image

7. docker ps: view the currently started container

8. docker build: create an image

9. docker load: load the image

The preceding commands are the main Commands of docker. We will use them later.

 

4. Use vs2017 for docker debugging

Here I use a. net core site as an example to enable the docker debugging function in 2017. If it is an existing project, right-click =, add =, and add Docker support.

1. Create a websample site

2. Introduction to the dockerfile

After the project is created, you can see a dockerfile in the project file. The content is as follows:

This file is a docker command file required for docker packaging. In vs, docker-compose and docker commands are integrated internally to complete image generation and container creation.

You will find that the debugging module is already docker. If you want to return to a normal previous project, delete the automatically generated docker-compose project under the solution.

We start debugging. If we open Kitematic, we will find that our websample container has been created and the dev tag is automatically added, for example:

 

 

5. Package A. net core site image

Here I use the. net core site I just created to demonstrate how to package an image without using vs after the site development.

1. Publish the site to the specified folder.

2. Go to the released folder and modify the docker file.

Check whether the docker file exists. If it does not exist, copy it from the project and modify the content as follows:

FROM microsoft/aspnetcore:1.0

WORKDIR /app
COPY . /app
EXPOSE 80

ENTRYPOINT ["dotnet", "websample.dll"]

A. Use microsoft/aspnetcore as the basic image

B. Create a working directory for the container

C. Copy the current project file to the app directory of the container.

D. Set the container to expose port 80 externally

E. Run the websample. dll command.

 

3. Create an image

Go to the file directory and run the docker build-t websample: latest. (The following points are required.

 

4. Run the current image

After the image is created, you can use the image to create the corresponding running container. run the following command: docker run-it-p 8000: 80 websample: latest

 

We can see that our container is running. We access 127.0.0.1: 8000.

 

 

 

So far, we have tried the basic functions of docker and hope this article will help you.

At the same time, I have recently developed a series of open-source OSS projects. common, OSS. http, OSS. social and OSS. if you are interested in several projects in PayCenter, please contact me or follow the public account OSSCoder

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.