0

I have just started learning Blockchain and following a YouTube tutorial . In that tutorial he installed ethereum by cloning the repo , but I have installed the ethereum/go-client using docker as per the instructions given in official documentation . I am beginner to Docker too . When I run the docker container using docker run -it -p 30303:30303 ethereum/client-go command , my terminal looks like this :- enter image description here

Now I want to make an account using personal.newAccount() command . But where I should run this command ? Container is not providing me any shell where I can run this command .

I have searched about this lot on internet but doesn't get a solution , all of them is showing how to install geth using docker only .

Please help me . I have just started learning blockchain .

Thank

1

Welcome to the Ethereum Stack Exchange.

The following should enable you to connect to the Geth console through the Docker container. There may be other ways of accomplishing the same thing.

  1. Find the name of the container running Geth

The following command will list all running Docker containers:

docker ps

make note of the name and/or id

  1. Connect to the container
docker exec -it <NAME OR ID> bash

This should put the terminal "in" the Docker container.

(Note: if this command gives you a no such file or directory: unknown. error, try replacing bash with sh, zsh, or ash. It depends on which shell is installed in the container by default. (Source)

  1. Create an account

Your reference to personal.newAccount() seems to be a reference to the Geth console. You'll need to find the .ipc file Geth creates while running and connect to it. You may already know where it is. If you don't, you should be able to use:

find / -name "geth.ipc"

make note of the path

  1. Open the Geth Console
geth attach path/to/geth.ipc

This should open the Geth JavaScript console in the terminal. You will now be able to use personal.newAccount()!

(Please note that this answer assumes that you want to use the Geth console, and not clef.)

Note: While researching the answer to this question, I came across something that might be useful for you. Running these commands as is will not save the data between sessions. That means that if you are syncing a public network (testnet or mainnet), that you'll need to restart syncing from the beginning every time you launch the container. If you'd like to save the sync data to disk, then when you run docker run, you should add the -v flag along with the path you want the data saved in, like this:

docker run -it -p 30303:30303 -v /path/on/host:/root/.ethereum ethereum/client-go

where /path/on/host is the directory the data should be saved in. (Source)

5
  • 2nd step is showing "OCI runtime exec failed: exec failed: container_linux.go:367: starting container process caused: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown" error May 20 at 12:29
  • I added a few alternatives, trying the same command with either sh or ash at the end should work (not sure which - it depends what shell is installed in your container). Let me know if it works!
    – Linum Labs
    May 21 at 6:57
  • I think installed shell is sh in container . But when I ran "geth attach home/rishabh/Desktop/geth.ipc" it shows me this error -"Unable to attach to remote geth: dial unix home/rishabh/Desktop/geth.ipc: connect: no such file or directory"_ whereas geth.ipc file is present on my desktop I can see it. May 23 at 15:34
  • that path (/home/rishabh) sounds like it's not in the Docker container - could it be that you are also running Geth in your regular env (not Docker), and that you searched for the ipc there (as opposed to in the terminal that is "inside" the Docker container)? Also, it looks like you may be missing a / at the beginning of the path (/home/ instead of home/)
    – Linum Labs
    May 24 at 7:14
  • I am running "geth attach home/rishabh/Desktop/geth.ipc" docker container May 28 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.