Use docker like apt and Yum

Source: Internet
Author: User
Tags docker hub

Apt and Yum and other package management tools can solve the dependencies of various packages under Linux, and with apt and Yum there is no need to manually compile the source code to solve the dependency relationship. Manual make source code, may lead to a lot of make,make to the final discovery of the kernel version of the requirements, then to make the kernel, and finally change the operating system.

Using apt and Yum is a lot easier, but there are times when there are some problems, because the various packages on an operating system are roughly the same period, for example, my gcc is October 2015 4.8,GLIBC is 2.8 in July 2015. If I wanted to replace GCC on my system with the 4.1 version of 2010, then I might glibc need to change to a 2011 version and then a chain of dependencies, and eventually the system won't work.

These are called " dependence on Hell (dependency Hell)". We often have these annoying problems when we deploy an application, I am in the test environment waste of the eldest brother deployment, to the release of production will have to be deployed again, it is possible to produce and test the environment operating system what is not the same. Using virtual machine can solve some problems, make good one VM image and throw it on hypervisor, but it's too heavy. Using containers (Container) can be a good solution, especially when Docker uses layered mirroring to make container mirroring easier to publish and migrate.


Docker is not a simple container software anymore, but an ecosystem. This article does not cover so much, just share how to use Docker like apt and Yum in everyday development, anyway I want to have a software (of course not graphical), I will use Docker first search, such as Nginx,tomcat, even DB2, IBM made the official db2-express image on the Docker hub.


Now there is a scenario where our application is a C language program that requires the GCC 5.1.0 to be compiled and run on Centos7. But I have only one Ubuntu server 14.04 locally, with nothing but Docker and SSH installed, and I want to use it to develop our app. If I install with APT, the default is 4.8. Now I use Docker to solve this problem.


Installing the development environment with Docker

First I need an editor, such as Vim or Emacs, and of course it's best to install it directly with apt, but I can use Docker for an editor. In fact, there is a good thing to do, said the latter. 650) this.width=650; "title=" 202726.png "alt=" 202726.png "src="/e/u261/themes/default/images/spacer.gif "class=" Ynote-attachment "style=" Background-image:url ("/e/u261/lang/zh-cn/images/localimage.png"); border:1px solid RGB ( 221,221,221); background-position:50% 50%; "/>

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/79/CE/wKiom1abgU7DG4bQAAB1rs4-CWA756.png "title=" 1.png " alt= "Wkiom1abgu7dg4bqaab1rs4-cwa756.png"/>

Vim is not official, official is the official version provided by the company or the community. But a lot of people have their own customized vim into a mirror placed on the Docker hub, can be used. The highest number of stars is Golang-vim-dev, which should integrate the Golang development environment, the next simple haron/vim. Execute the sudo docker pull Haron/vim directly.


Then we need to install GCC 5.1.0 and search first.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/79/CD/wKioL1abgtrzvQYsAADJF0FfhZA313.png "title=" 2.png " alt= "Wkiol1abgtrzvqysaadjf0ffhza313.png"/>650) this.width=650; "title=" 835147.png "alt=" 835147.png "src="/e/ U261/themes/default/images/spacer.gif "class=" ynote-attachment "style=" Background:url ("/e/u261/lang/zh-cn/images /localimage.png ") no-repeat center;border:1px solid #ddd;"/>

This official, official is the official GCC mirror. Performing Docker Pull gcc:5.1.0

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/79/CD/wKioL1abgvvz6RfgAACHxxnBADI609.png "title=" 3.png " alt= "Wkiol1abgvvz6rfgaachxxnbadi609.png"/>



Finally we also need a CentOS 7 operating environment, as well as the official, direct sudo docker pull centos:7 can be downloaded.

650) this.width=650; "title=" 288452.png "alt=" 288452.png "src="/e/u261/themes/default/images/spacer.gif "class=" Ynote-attachment "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px Solid #ddd; "/>650) this.width=650;" Src= "http://s4.51cto.com/wyfs02/M02/79/CE/wKiom1abgu2DNfgxAABdR_ Gv6xg178.png "title=" 4.png "alt=" Wkiom1abgu2dnfgxaabdr_gv6xg178.png "/>



Pull down all the things you need and look at the local mirrors.

650) this.width=650; "title=" 35456.png "alt=" 35456.png "src="/e/u261/themes/default/images/spacer.gif "class=" Ynote-attachment "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px Solid #ddd; "/>650) this.width=650;" Src= "http://s4.51cto.com/wyfs02/M02/79/CE/wKiom1abgv_ Sjy-qaadxpp6z7dw619.png "title=" 5.png "alt=" Wkiom1abgv_sjy-qaadxpp6z7dw619.png "/>

Gcc5.1.0,centos7 and Vim are already available locally.


Development testing and operation

How do I open a file with vim?

If the path of test.c is/home/niuxinli/test.c, use

Docker run-it--rm-v/home/niuxinli/test.c:/test.c Haron/vim vim/test.c

Can open the test.c in the container, if too long can write an alias or script.

The meanings of each of these options are:

-it:interactive+tty Interactive and assign a pseudo terminal--RM: Delete the container-v/home/niuxinli/test.c:/test.c the host/home/niuxinli/test.c map to the container when exiting the container TEST.c, V is the meaning of volume vim/test.c in the container to execute the VIM/TEST.C, when the vim command to see the file system directory is in the container, need to use the path inside

We use a different way to directly map the working directory of the host to the container.

Create a new working directory/home/niuxinli/appworkspace, then mount it in the container and use Vim to edit various source code in the container. The advantage is that we can let developers see only what is in this directory and not affect each other.

Docker run-it--rm-v/home/niuxinli/appworkspace:/appworkspace Haron/vim/bin/bash

This time, open a bash and open the file in/appworkspace with Vim.

650) this.width=650; "title=" 795774.png "alt=" 795774.png "src="/e/u261/themes/default/images/spacer.gif "class=" Ynote-attachment "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px Solid #ddd; "/>650) this.width=650;" Src= "http://s3.51cto.com/wyfs02/M00/79/CD/wKioL1abg7yh7SKAAADE_ Ve6akm511.png "title=" 6.png "alt=" Wkiol1abg7yh7skaaade_ve6akm511.png "/>

Now we can program in the Appworkspace, the image of the author's configuration is very good, automatic indentation highlighting.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/79/CD/wKioL1abg9TgrQ7vAABJzj7bodQ833.png "title=" 7.png " alt= "Wkiol1abg9tgrq7vaabjzj7bodq833.png"/>650) this.width=650; "title=" 891355.png "alt=" 891355.png "src="/e/ U261/themes/default/images/spacer.gif "class=" ynote-attachment "style=" Background:url ("/e/u261/lang/zh-cn/images /localimage.png ") no-repeat center;border:1px solid #ddd;"/>

The test.c is also produced in the/home/niuxinli/appworkspace after saving. The following is the compilation, again, we map the/home/niuxinli/appworkspace to the GCC container, and then a bash process, compiled with GCC.

650) this.width=650; "title=" 253788.png "alt=" 253788.png "src="/e/u261/themes/default/images/spacer.gif "class=" Ynote-attachment "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px Solid #ddd; "/>650) this.width=650;" Src= "http://s5.51cto.com/wyfs02/M01/79/CD/ Wkiol1abhcjj3yf5aaf0a7x8fhk825.png "title=" 8.png "alt=" Wkiol1abhcjj3yf5aaf0a7x8fhk825.png "/>

With GCC 5.1.0 compiled, need to put down centos7 inside run.

650) this.width=650; "title=" 774998.png "alt=" 774998.png "src="/e/u261/themes/default/images/spacer.gif "class=" Ynote-attachment "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px Solid #ddd; "/>650) this.width=650;" Src= "http://s5.51cto.com/wyfs02/M01/79/CE/ Wkiom1abg8bbvf3baaidib39omk580.png "title=" 9.png "alt=" Wkiom1abg8bbvf3baaidib39omk580.png "/>



Summarize

In fact, there is a problem with this, our HelloWorld is very simple and only for demonstration purposes. For complex programs, there are still dependencies, such as the link library in the GCC mirror conflicts with the library inside the Centos7, and may not work in CENTOS7. The correct way is to make a centos7+gcc5.1 image, both compiled with this container, and run with it, the development test production with the compilation run environment is consistent, this is the Docker build, ship and run any app anywhere.


This article is from the "Niu Blog" blog, make sure to keep this source http://nxlhero.blog.51cto.com/962631/1735922

Use docker like apt and Yum

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.