Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to compile etcd using Docker Container Source Code

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to use Docker container source code to compile etcd, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Background

Etcd is a distributed key-value pair repository developed by CoreOS. In Kubernetes, we need to use etcd as the persistent storage for all REST API objects.

Unfortunately, in github's release, CoreOS puts etcd's binary executables on Amazon's S3 storage, which is very slow to access domestically. Therefore, we can only compile etcd from source code.

Process

1. Download etcd source code.

$git clone https://github.com/coreos/etcd.git$ cd etcd

two。 According to the actual situation, choose the appropriate version. For example, I am using version 2.2.1 here.

$git checkout-b v2.2.1

3. Compile the source code. Run the build executable for this directory.

$. / build

However, there was an error running the command, prompting that context could not be found.

. / buildgopath/src/github.com/coreos/etcd/cmd/vendor/github.com/coreos/etcd/lease/leasehttp/http.go:19:2: cannot find package "context" in any of: / root/etcd/gopath/src/github.com/coreos/etcd/cmd/vendor/context (vendor tree) / usr/local/go/src/context (from $GOROOT) / root/etcd/gopath/src/context (from $GOPATH) / Go/src/context / go/src/app/_gopath/src/context

After searching the Internet, it turns out that etcd needs to be compiled in an environment above Golang1.7, but I am using Ubuntu16.04, the default Golang version is 1.6, and there is no context package. Therefore, we need to install the Golang1.7 environment.

4. Compile using the Docker container. Because my Golang environment also runs other packages, in order not to affect the operation of other packages. I use Golang1.7 's docker container directly to compile etcd here.

$sudo docker run-v / home/newbee/etcd/:/opt/etcd-it-- rm golang:1.7.5 bash# cd/ opt/etcd#. / build

In the-v parameter, / home/newbee/etcd is my etcd directory in Docker host (that is, my server's), and / opt/etcd is the mapping directory in my container. Note: it takes some time to download the golang image from Docker hub. When the download is complete, you enter the container, then cd to the / opt/etcd directory and perform the compilation.

After the compilation is complete, check to see if there are any executable files in the bin directory of etcd. If so, the compilation is successful. Then exit the container, and there is a corresponding executable file in the server's etcd directory.

Etcd needs to be compiled in a version above Golang1.7.

Docker container can easily provide Golang environment without affecting the original environment, which is a new way of thinking.

The above is how to use the Docker container source code to compile etcd, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 233

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report