In our life, we often encounter such a situation that in order to learn a certain technology, we need to buy a computer with a relatively high configuration and obtain the cloud server from the cloud server provider. Whichever way you choose, there will always be a cost.

Is there any way to get things done for free, or do big things with less money?

Test interview Guide

Today, I’m going to show you a method that can be applied to your benefits indefinitely.

  • First, install VirtualBox software on your computer. As for your own computer, it doesn’t matter.

  • Then, download iOS files for CentOS7 (other Linux iOS files will work)

  • Then, install the CentOS7 system with VirtualBox. When configuring information, set the disk size to a larger size. You can set the CPU and memory size according to the actual situation of your computer.

  • Then, in your installed Linux, install the Docker

    The installation

    curl -fsSL get.docker.com | bash -s docker –mirror Aliyun

    or curl -sSL get.daocloud.io/docker | sh

    Configuration acceleration is optional

    vim /etc/docker/daemon.json {“registry-mirrors”:[“reg-mirror.qiniu.com/”]}

    Start the docker

    systemctl enable docker systemctl restart docker

  • Then, in the virtual machine, download any Linux OS images you want

    For example, download the centos7 image

    docker pull daocloud.io/library/centos:7

Other versions of Linux, or other Linux, can be downloaded at hub.docker.com

  • Then, using the image downloaded in the previous step, create the Liunx container

    Privilege mode is enabled when creating the container, otherwise executing certain commands in the container will be reported

    Failed to get D-Bus connection: Operation not permitted

    Docker run – itd – name container name – ring = true: -p hosting port container port daocloud. IO/library/centos: 7 / usr/sbin/init

  • Then, go into the container and install the software you want

    Into the container

    Docker exec -it container name /bin/bash

    After entering, you can install any software you want

Now that you’ve created a virtual Linux machine with VirtualBox, you can create any version of the Linux container you want. Once inside the container, you can use it just like a normal Linux machine.

Now, in the learning phase, if you want to practice installing software and setting up your environment on a Linux machine, you can do it in this Linux container.

But it’s not perfect.

For example, if you want to install some software in Linux, you already have the installation package, you want to use the package directly, do not want to download it in the container; The other thing is, when you build a service in a Linux container, and you try to access the service through your local browser, you can’t. How do you do that?

  • First of all, we have to learn a new docker named, copy cp command, master the test of this command, no longer afraid of file transfer problems.

    Docker cp command

    Copies files from the host machine to the container

    Docker cp [OPTIONS] SRC_PATH | – CONTAINER: DEST_PATH docker cp hosting file path name of vessel: / CONTAINER path

    Copies files from the container to the current local path

    Docker cp [OPTIONS] CONTAINER: SRC_PATH DEST_PATH | – docker cp CONTAINER name: $PWD/CONTAINER file path

  • Next, we also need to master, make your own private image command.

    Let’s stop the container

    Making a Private Image

    docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

    The OPTIONS:

    -a: submits the mirror author.

    -c: use the Dockerfile command to create an image.

    -m: Description of submission;

    -p: Suspends the container at commit time.

    Example:

    Docker commit -a “Allen” -m “This is a case” container name custom image name: Tag version

    -a-m can be omitted;

    Custom mirror name: The tag version can also write only the custom mirror name

Once the environment is set up, you already know which ports to open. Write down the ports yourself. Then, get out of the container, stop the container, and start making the container your own private image. After the image is successfully created, you can create a new container with your own private image. Add the -p parameter to open the port when creating the container. In this way, you do not need to worry about the port is not enough.

Docker run-itd --name privileged=true --privileged=true -p host port: privileged port private image name :tag versionCopy the code

With these steps, you can basically build containers indefinitely to practice on, and if the exercise fails, it only takes a few seconds to create a new Linux container, and you have a whole new Linux system.

If you still want to save your own private image, or transfer it to another computer, you can continue to read.

If this requirement is in the same LAN, you can save the private image first, and then use FTP (SCP) to transfer to each other; If it’s not on a LOCAL network, save the private image first, download it locally, and then send it to the other party. Test interview Guide

Docker save -o IMAGE [IMAGE...] Docker save -o cnginx:0.1 # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = # import step generated image file on the docker load [OPTIONS] OPTIONS: - input - I: Specify the file to import instead of STDIN. --quiet, -q: condenses the output information. # instance docker -i pnginx.tarCopy the code