geth docker
by Vince Tabora
通过文斯·塔博拉(Vince Tabora)
如何从Docker容器运行GETH (How to run GETH from a Docker container)
Installing the Ethereum node client on a machine can be a tedious process. There is a simpler way this can be done using a Docker client. This is a guide for running the GETH (Ethereum-Go) node client from inside a Docker container. GETH is the GoLang implementation of the Ethereum protocol. There is an image available to pull from the Docker hub repository that can run the environment.
在机器上安装以太坊节点客户端可能是一个乏味的过程。 有一种更简单的方法可以使用Docker客户端来完成。 这是从Docker容器内部运行GETH (以太坊-Go)节点客户端的指南。 GETH是以太坊协议的GoLang实现。 可以从可运行环境的Docker中心存储库中提取图像。
The GoEthereum website lists the following available images with descriptions.
以太坊 网站 列出以下可用的图像及其说明。
ethereum/client-go:latest
is the latest develop version of Gethethereum/client-go:latest
是Geth的最新开发版本ethereum/client-go:stable
is the latest stable version of Gethethereum/client-go:stable
是Geth的最新稳定版本ethereum/client-go:{version}
is the stable version of Geth at a specific version numberethereum/client-go:{version}
是Geth在特定版本号上的稳定版本ethereum/client-go:release-{version}
is the latest stable version of Geth at a specific version familyethereum/client-go:release-{version}
是Geth在特定版本系列上的最新稳定版本
The following ports are opened by default when running from the container.
从容器运行时,默认情况下打开以下端口。
8545
TCP, used by the HTTP based JSON RPC API8545
TCP,由基于HTTP的JSON RPC API使用8546
TCP, used by the WebSocket based JSON RPC API8546
TCP,由基于WebSocket的JSON RPC API使用30303
TCP and UDP, used by the P2P protocol running the network30303
TCP和UDP,由运行网络的P2P协议使用30304
UDP, used by the P2P protocol's new peer discovery overlay30304
UDP,由P2P协议的新对等发现覆盖使用
The Docker client software must be installed on the machine you are going to run the container from. Containers can only run if you have the Docker client installed. Depending on your operating system, the correct version of the client will be needed.
Docker客户端软件必须安装在要从其运行容器的机器上。 只有安装了Docker客户端,容器才能运行。 根据您的操作系统,将需要正确版本的客户端。
There are separate versions for Windows, Linux and the MacOS. The container can even be run on a Linux instance running on AWS, like a typical Linux installation. Once the Docker client is installed, the underlying platform doesn’t matter. The commands will be the same for all.
Windows,Linux和MacOS有不同的版本。 该容器甚至可以在AWS上运行的Linux实例上运行,例如典型的Linux安装。 一旦安装了Docker客户端,基础平台就没有关系了。 所有命令都相同。
获取图像 (Getting The Image)
Open a terminal on Linux or MacOS, or PowerShell command prompt from Windows. In the CLI prompt, type the following command:
在Linux或MacOS上打开终端 ,或者从Windows打开PowerShell命令提示符。 在CLI提示符下,键入以下命令:
docker pull ethereum/client-go
码头工人拉以太坊/客户端去
This pulls the Docker image from the hub repository where it was uploaded by the Ethereum developers. Once you have issued this command, the following verbose or similar should be displayed:
这将从以太坊开发人员上载的中心存储库中提取Docker映像。 发出此命令后,应显示以下详细信息或类似内容:
I have already pulled the image, so the verbose may look different. When you issue the pull command it will always download the latest image available, which is good practice.
我已经提取了图像,所以详细的外观可能有所不同。 发出pull命令时,它将始终下载可用的最新映像,这是一个好习惯。
运行节点 (Running The Node)
Now you can start the node by issuing the following command:
现在,您可以通过发出以下命令来启动节点:
We want to run the node with the flag options -i and -t to display information from our container. The -p indicates the use of a port number, in this case 30303. Likewise, the command can be run without the flags and it will simply use the default ports and settings from inside the container.
我们希望使用标志选项-i和-t运行节点以显示来自容器的信息。 -p表示使用端口号,在这种情况下为30303。同样,该命令可以在不带标志的情况下运行,它将仅使用容器内部的默认端口和设置。
The following information should appear from the terminal.
以下信息应从终端出现。
The INFO line that shows the config reveals what the node client software has installed. The node client is running the latest (as of this posting) version of the Ethereum software which is Constantinople that is a user activated hard fork at block height 7280000.
显示配置的INFO行显示了节点客户端软件已安装的内容。 节点客户端正在运行以太坊软件的最新版本(截至本文发布),该版本是君士坦丁堡,这是用户激活的硬叉,块高度为7280000。
When running in JSON-RPC API:
在JSON-RPC API中运行时:
Take note that running the option rpcaddr “0.0.0.0” is not secure, since you are opening up your node to all traffic. If your ETH wallet were unlocked, a hacker can get to your node in this way and take your coins. I don’t cover security in this article, but you can read more about that here (securing your GETH node’s RPC ports). Always abide to safe and best practices.
请注意,运行选项rpcaddr“ 0.0.0.0”并不安全,因为您正在向所有流量开放节点。 如果您的ETH钱包被解锁,黑客可以通过这种方式到达您的节点并拿走您的硬币。 我不会在本文中讨论安全性,但是您可以在此处阅读有关此内容的更多信息(保护GETH节点的RPC端口)。 始终遵守安全和最佳做法。
If the node displays the following in the INFO line, there will be a problem:
如果该节点在INFO行中显示以下内容,则将出现问题:
config=”{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Constantinople: <nil> Engine: ethash}”
config =” {ChainID:1家园:1150000 DAO:1920000 DAOSupport:真正的EIP150:2463000 EIP155:2675000 EIP158:2675000拜占庭:4370000君士坦丁堡:<nil>发动机:ethash}”
The Constantinople: <nil> indicates the software was not updated. There is also no line for ConstantinopleFix, which appears in the correct configuration.
君士坦丁堡:<nil>表示软件未更新。 ConstantinopleFix也没有一行,它以正确的配置显示。
持续数据 (Persistent Data)
For persistent blockchain data, Docker data volumes should be used with the option -v. The /path/on/host
should be replaced with the location you specify. For this the following command must be used:
对于永久性区块链数据,应将Docker数据卷与-v选项一起使用。 /path/on/host
应该替换为您指定的位置。 为此,必须使用以下命令:
检查节点状态 (Checking Node Status)
You can check the container’s status using the following command:
您可以使用以下命令检查容器的状态:
docker ps
码头工人ps
This will display the Container ID with the image name, status and ports used.
这将显示容器ID以及图像名称,状态和使用的端口。
#These are the commands to run from the Docker CLI to run the Ethereum Go node client
#GETTING THE IMAGE
docker pull ethereum/client-go
#RUNNING THE NODE
docker run -it -p 30303:30303 ethereum/client-go
#RUNNING NODE USING API
docker run -it -p 8545:8545 -p 30303:30303 ethereum/client-go --rpc --rpcaddr "0.0.0.0"
#Note, warning about using --rpcaddr "0.0.0.0" in a live environment. It is an insecure way of opening your node.
#There are different ways to secure your ports, but this is one thing to take note of if you plan to use the API.
#PERSISTENT DATA
docker run -it -p 30303:30303 -v /path/on/host:/root/.ethereum ethereum/client-go
Take note that this does not automatically mine ETH. That is a different process. For getting quick access to the Ethereum blockchain, this is the purpose for running GETH.
请注意,这不会自动开采ETH。 那是一个不同的过程。 为了快速访问以太坊区块链,这是运行GETH的目的。
For full code source, visit: https://github.com/Play3rZer0/GETHDocker.git
有关完整的代码源,请访问: https : //github.com/Play3rZer0/GETHDocker.git
翻译自: https://www.freecodecamp.org/news/how-to-run-geth-from-a-docker-container-b6d30620ca74/
geth docker