Building a Go-ethereum node based on Docker (on)

Reference link: https://github.com/ethereum/go-ethereum/wiki/Running-in-Docker

Original reprint: http://dockone.io/article/1931

The Ethereum Go (language) team builds a Docker image of a "geth" node as part of its continuous build chain. We can use these images to quickly run an Ethereum node in our local environment. In this article we will use Docker to build an Ethereum working and development environment.

## A full Ethereum node ##
The first test is to download the current Ethereum go-client ("geth") image and start a client node connected to the Ethereum production network.

87b36ff.jpg

Now, we start a simple node as described in the Ethereum documentation. Once the block sync starts, use CTRL + C to stop the node. We are not going to use this container, so there is no need to download the entire chain data for now.
60a33d6.jpg

0b6e4ed.jpg

d165227.jpg

Above, we started the Docker container using the RUN command. RUN creates a new container with an image called "ethereum/client-go" and starts the entry point "/usr/bin/geth" defined by this image.

The following parts need to be understood:
  1. RUN always creates a new container. This means that every time we start a container by using RUN, we will end up with a lot of useless containers. Once a container is created, the correct way to restart it is with the START command.
  2. Command line arguments after Docker RUN command -it -p 30303:30303. The "-it" equivalent to "-i -t" stands for "interactive" and "terminal device (tty)". Without these instructions, the container will run in the background and give no feedback to our terminal. "-p 30303:30303" instructs Docker to expose port 30303 from inside the container to the host and other containers as port number 30303. The container is an isolated environment, and this port is not implicitly exposed, and the Ethereum client inside the container will not be able to contact the outside world and the blockchain. 30303 is the default Ethereum peer-to-peer network port. Additional parameters following the image name are used for commands where the image is defined as the starting point at startup. Not set in this example. 3. Another important thing is where the blockchain data is stored in this test. By default, "geth" uses "$userhome/.etherum" as the default data directory. When running inside a container, "root" if not specified: "/root/.ethereum". However, this place is "inside" the container on its "virtual disk". Keeping the data inside the container keeps it isolated from the host and other containers, which is not necessarily what we want.

In this example, the node needs to download the entire blockchain data. This requires a lot of time, bandwidth and storage space, and sharing these files between various containers and hosts can become very difficult.
Shared databases are obviously a typical problem when running larger applications, and Docker offers a variety of options in this regard. In previous versions of Docker, people often used so-called "data containers". These are classic and specialized containers, independent of application runtime instances dedicated to storing data. The current version of Docker replaces this idea with so-called VOLUMES. In this article, we will use a different solution: we store the blockchain and account data on the host's disk and mount the directory into the container. This has some advantages for Ethereum, which we will cover later.

Before continuing, let's see what mirrors we currently have in our installation:
0db301e.jpg

Next, let's list if our container instance is running. The active container must be specified by adding the "-a" command:
7461917.jpg
The INSPECT command is very handy, it shows the entire configuration and situation of the container.
c33a7df.jpg

Our current container was previously created with the RUN command, now we will restart the instance with the START command:
4859026.jpg

"-i" stands for outputting the container to our terminal, "d8" stands for the container ID, it can also be the image name, there is no need to enter the full ID, as long as it is unique.
Alternatively, we can start the container in the background and connect the terminal later.
4b86965.jpg
or:
49d5dde.jpg
404268a.jpg
Complete this test and understand the basics described above. In the next article, we will start our blockchain journey!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325357015&siteId=291194637