[Docker linux] Linux system image is converted to docker image

Overview

Everyone who uses docker to install linux knows that if you install the linux system in the warehouse provided by docker, you will experience the most streamlined and purest linux system. Of course, he will streamline that you even ifconfigneed to configure the commands yourself For me, this is not what I want. If I use VMware to install the linux system, but I have used docker, I cannot use vmware. Then you will ask, can't docker and vmware be used at the same time?

So, I tell you, yes.

The problem lies here. There are a lot of articles on the Internet that talk about the difference between docker and vmware, but few articles explain the difference between the virtual technologies they use on windows.

The current Windows client officially produced by Docker is called Docker Desktop for Windows. One of the conditions for its normal operation is that the system opens the Hyper-V virtualization service. As mentioned above, Hyper-V is a Type-1 Hypervisor, which will This makes software such as VMware and other Type-2 Hypervisors inoperable.
At this point, conflicts have emerged: Docker clients using Hyper-V technology and other Type-2 Hypervisors cannot run at the same time. You must restart and shut down Hyper-V to run other programs again. Type-2 Hypervisor software.

Excerpt from the coexistence of Docker and VMware under Windows

@

Then after knowing the reason, we must start to solve it. I do n’t want to use docker and VMware to switch back and forth. The initial stupid way is to use vmware on another system (I installed a dual system) and docker on windows. Anyway, the virtual machine is only in It ’s used in class, but it ’s not right to recall, is n’t it more troublesome?

Looking back, since docker can install the linux system, can I use my own image file to import it?

I exported the original linux system installed in docker to check its internal structure. Isn't this the common linux file? So I only need to compress the original linux system into a docker image file, and then import it into docker. Haven't all the problems been solved?

If you haven't installed docker yet, see: Application container engine docker installation worth learning

One: the process

First, package the Linux image

Packaging the Linux system should be streamlined. Some temporary files are not needed, so there is no need to package, just need to package what we need. Use the following command, remember to add sudo, package all linux files system.tar, save in the tmp directory, exclude some unnecessary directories, and don't forget a point at the end.

tar -cvpf /tmp/system.tar --directory=/ --exclude=proc --exclude=sys --exclude=dev --exclude=run --exclude=boot .

2. Export from linux system to physical machine (windows)

If you have a small partner, you can complete the first and second steps in Vmware on his computer, and then use the ftp tool to export.

After packaging, I will export the compressed package, because I have installed a hadoop、hbase、zookeeper、hiveseries of things, he is now 2.57GB size.

Please ignore this paragraph: (I exported the file from the deepin system to windows, record it here for future use, windows and linux dual system file system is not shared, deepin file system cannot be accessed in windows, but Windows files can be read in Deepin, but cannot be written. So how do I get Windows in the compressed package in Deepin (Linux)? At this time, the artifact linux readercame out and can be used to read and write Deepin's file system in Windows. Things are very nice)

Three, import into docker

In cmd, import the compressed package that was just compressed. Here you must go to the directory where system.tar is located. Otherwise, you can directly add the absolute path of system.tar, otherwise you will definitely get an error and cannot find the file.

docker import system.tar

After importing and using the docker imagesviewing image, there will be an unnamed image with no label. At this time, we need to label the image for future use and viewing

Fourth, label

Use the docker tagcommand to label your mirror, followed by the mirror id and the warehouse name: label.

docker tag [镜像id] linux/centos:hadoop


At this point, you have more than half of your success. At this time, the image is ready and you need to use the image to run a container.

Five, run the container

Use the following command to run the image you created yourself, pay attention to the following /bin/bash.

docker run -t -i [镜像id] /bin/bash

Test, um, java is still there, then everything else is still there.

Well, by now, great work has been done.

Two: docker related operations

一、docker save

Save the image file as a local file.

Usage:  docker save [OPTIONS] IMAGE [IMAGE...]

Save one or more images to a tar archive (streamed to STDOUT by default)

Options:
  -o, --output string   Write to a file, instead of STDOUT

例子:docker save -o mysql.tar mysql:latest

二、docker import

Export the container as a local file

Usage:  docker export [OPTIONS] CONTAINER

Export a container's filesystem as a tar archive

Options:
  -o, --output string   Write to a file, instead of STDOUT
  
例子:docker export -o mysql.tar

Three, docker load

Read image file from local

Usage:  docker load [OPTIONS]

Load an image from a tar archive or STDIN

Options:
  -i, --input string   Read from tar archive file, instead of STDIN
  -q, --quiet          Suppress the load output

例子: docker load -i mysql.tar

四、docker import

Create an image from a local file

Usage:  docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]

Import the contents from a tarball to create a filesystem image

Options:
  -c, --change list      Apply Dockerfile instruction to the created image
  -m, --message string   Set commit message for imported image

例子:docker import mysql.tar

Suggestions: Generally use a combination of save and load, and use a combination of export and import.

The author has something to say

Well, as of this post, I compromised with him again, because the content of the container I imported in docker was modified. After restarting, he will not take effect, and no useful method has been found If you have a solution, please leave a message to tell the author, I will be grateful, but this blog can still be used as my notes for later review, the final method I use is to close Hyper-v when I need to use a virtual machine .

1,如果用docker,
第一步:在控制面板中勾选Hyper -v
第二步:在cmd,以管理员身份运行:
bcdedit /set hypervisorlaunchtype auto
第三步;重启

2,开启虚拟机linux
第一步:在控制面板中取消勾选Hyper -v
第二步:在cmd中,以管理员身份运行:
bcdedit /set hypervisorlaunchtype off
第三步;重启

Method reference: docker and virtual machine incompatibility

Guess you like

Origin www.cnblogs.com/lomtom/p/12686672.html