Use Docker to build a Linux environment on windows10 professional edition

Use Docker to build Linux and configure the environment in Window10

One, what is Docker

Docker is an open source application container engine, based on the Go language and open source in compliance with the Apache2.0 protocol.

Docker allows developers to package their applications and dependent packages into a lightweight, portable container, and then publish it to any popular Linux machine, which can also be virtualized.

Containers use the sandbox mechanism completely, and there will be no interfaces between each other (apps similar to iPhone), and more importantly, the container performance overhead is extremely low.

Second, the application scenarios of Docker

  • Automated packaging and publishing of web applications.
  • Automated testing and continuous integration and release.
  • Deploy and adjust databases or other background applications in a service-oriented environment.
  • Compile or extend the existing OpenShift or Cloud Foundry platform from scratch to build your own PaaS environment.

Three, the advantages of Docker

Docker is an open platform for developing, delivering and running applications. Docker enables you to separate your application from the infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same way you manage applications. By leveraging Docker's method to quickly deliver, test, and deploy code, you can greatly reduce the delay between writing code and running it in a production environment.

1. Deliver your application quickly and consistently

Docker allows developers to use the local containers of the applications or services you provide to work in a standardized environment, thereby simplifying the development life cycle.

Containers are very suitable for continuous integration and continuous delivery (CI/CD) workflows

2. Responsive deployment and expansion

Docker is a container-based platform that allows highly portable workloads. Docker containers can be run on the developer's native machine, on a physical or virtual machine in the data center, on a cloud service, or in a hybrid environment.

Docker's portability and lightweight features can also enable you to easily complete the workload of dynamic management, and according to business needs instructions, real-time expansion or removal of applications and services.

3. Run more workloads on the same hardware

Docker is light and fast. It provides a feasible, economical, and efficient alternative to virtual machines based on hypervisors, so you can use more computing power to achieve business goals. Docker is very suitable for high-density environments and small and medium-sized deployments, and you can do more with fewer resources.
(The above are all from the website https://www.runoob.com/docker/docker-tutorial.html )

Fourth, install Docker

Check Hyper-V

Docker supports Windows 10 Pro and Hyper-v needs to be turned on.
Control Panel->Programs->Enable or Disable Windows Function
Insert picture description here
Select the red box part (ignore this, it has been selected before, I try to laugh quietly)
, please make sure to check Hyper-V before downloading the Docker installation package.

Download the Docker installation package

Go to the official website to download the Docker installation package. The
official website provides https://docs.docker.com/docker-for-windows/install/ and
Insert picture description here
Insert picture description here
click to start downloading. After the
download is complete, double-click the installation package to install the Docker application.
The interface after installation is as shown in the figure below
Insert picture description here
(ignore the existing image).
If such an error occurs when opening it,
Insert picture description here
click the blue link to enter the website to update the WSL, then the problem can be solved.
At this point, the installation is over and the environment is set up.

Register and log in to Docker

If you want the push to succeed, you need to go to the official website to register the docker username
https://hub.docker.com/

Linux mirror download and related software download (vim, gcc, gdb)

Configure the acceleration source (under the premise that you have logged in)

As we all know, Docker's official server is abroad, so we need to configure the accelerator to pull the mirror.
Click the settings button in the interface to enter the settings page
Insert picture description here
as shown
in the figure. Add the address after the registry-mirrors column as follows: the
Insert picture description here
address is
"https:// xxxxxx.mirror.aliyuncs.com",
"http://hub-mirror.c.163.com"
(the acceleration address is not unique, you can choose to replace it if there is a better one)
Apply & Restart Docker Make configuration changes and restart the Docker application

View Docker version

Now enter the windows terminal (that is, the windows command line win+r, enter cmd and press Enter)
Insert picture description here

Check the version of Docker, you can also check whether Docker is installed successfully. The
command is

 Docker --version

The installation is successful as shown below
Insert picture description here

pull Ubnutu (other images can also be pulled, if you need other versions, you can change the command by yourself)

As shown below, the mirror image is being pulled down Ubantu. The
Insert picture description here
command is `

 docker pull ubuntu:latest

or

 docker pull ubuntu(默认为最新版本)

The following picture shows the pull-down success.
Insert picture description here

Environment configuration

Next, we will configure the Ubantu environment

View current mirror

The command is

docker images

Insert picture description here

Run the current image

The command is

docker run -it name(镜像的名字)

Insert picture description here
You can see that the terminal header has been changed, which means that the image has created a container instance and has entered the instance

View container status

Need to exit the container
command is

exit

The successful exit is as shown below
Insert picture description here
. The command to view the status is

docker ps -a

Insert picture description here
(Please ignore my so many containers)

Install, edit, compile and debug environment

First we need to update the download source
command as

apt-get update

Insert picture description here
After the update is complete, you can install other software.
Next, install the vim
command as

apt-get install -y vim

Wait for the installation to complete,
Insert picture description here
check whether the installation is complete (check version)
command is

vim --version

Insert picture description here

The installation gcc
command is

apt-get install gcc

Insert picture description here

Check whether the installation is complete (check version)
command is

gcc --version

Insert picture description here

The
command to install gdb is

apt-get install gdb

Insert picture description here
You need to make two choices
Insert picture description here
during installation. We choose 6
Insert picture description here
time zone here. Here we choose
19 to
see if the installation is complete (check version). The
command is

gdb --version

Insert picture description here

So far, the basic environment of vim/gcc/gdb has been successfully built.

Save the image

Remember,
be sure to save.
Be sure to save.
Be sure to save. The
important thing is said three times. If you don’t save, the installed editing and compiling environment will be lost
. When you open it again, you need to reinstall
it. When you save, you need to exit the container. The
Insert picture description here
save command is

docker commit -m "系统信息" -a "docker账户名字" id yonghuxinxi/name
例如
docker commit -m "xitong" -a "hang" da50855dce8e hang/ubuntu

Insert picture description here
At this point we need to check whether to save or not.
Use the command

docker images

Insert picture description here
If there is a mark in the figure, it is successfully saved.
If you want to run the mirror again, the
command is

docker run -it hang/ubuntu
push to docker hub

If you want to use the configured image in other servers, you need to push the image to the docker hub
command as

docker push name

Insert picture description here
If you are pushing as shown in the figure below
Insert picture description here, please refer to the following article
https://blog.csdn.net/qq_46140800/article/details/114289043
next time on other servers, install docker directly, configure the accelerator, and log in to yourself Account, directly docker pull 2211510676/ubuntu can pull down the mirror you are pushing to docker hub. If you need to update the environment configuration again, push again in the same way.

Five, the end

So far this article is over. Please correct me if there are any errors. If necessary, you can leave a message, cheer together and work together.
Borrowed from

https://www.icode9.com/content-3-827951.html

Guess you like

Origin blog.csdn.net/qq_46140800/article/details/114282781