Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot obtain a lock on data directory #18

Closed
ekkis opened this issue Jul 3, 2016 · 11 comments
Closed

Error: Cannot obtain a lock on data directory #18

ekkis opened this issue Jul 3, 2016 · 11 comments

Comments

@ekkis
Copy link

ekkis commented Jul 3, 2016

I'm trying to run bitcoind from the docker image like this:

docker run --rm -it --name bitcoind -p 8332 -v ${PWD}/bitcoind:/home/bitcoin/.bitcoin seegno/bitcoind:latest -server -printtoconsole

but I'm getting the error below:

/entrypoint.sh: assuming arguments for bitcoin
/entrypoint.sh: setting data directory to /home/bitcoin/.bitcoin

2016-07-03 05:57:12
[many empty lines]
2016-07-03 05:57:12 Bitcoin version v0.12.0 (2016-02-17 09:40:03 +0100)
2016-07-03 05:57:12 InitParameterInteraction: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1
2016-07-03 05:57:12 Error: Cannot obtain a lock on data directory /home/bitcoin/.bitcoin. Bitcoin Core is probably already running. No such file or directory.
Error: Cannot obtain a lock on data directory /home/bitcoin/.bitcoin. Bitcoin Core is probably already running. No such file or directory.
2016-07-03 05:57:12 Shutdown: In progress...
2016-07-03 05:57:12 StopNode()
2016-07-03 05:57:12 Shutdown: done

the directory I've created to host the blockchain (and presumably the wallet) looks like this:

drwxr-xr-x 2 ekkis staff 68 Jul 2 22:46 bitcoind/

so what am I doing wrong? the container doesn't have sufficient space in it for a sync so I need to write it to my local disk.

incidentally I'm running this on OSX using Boot2Docker, which I understand maps my /home folder automatically to the the docker-machine's file system. I've also verified that there is no bitcoind/.lock file.

@ekkis
Copy link
Author

ekkis commented Jul 3, 2016

ok, I tried running it manually:

docker run --rm -it --name bitcoind -p 8332 -v ${PWD}/bitcoind:/home/bitcoin/.bitcoin --entrypoint=/bin/bash seegno/bitcoind:latest

and then, inside the container:

root@dbf45e2d4a42:/# bitcoind -server -printtoconsole -datadir=/home/bitcoin/.bitcoin
but now I see a different error:

2016-07-03 06:45:54 * Using 65.5MiB for in-memory UTXO set
2016-07-03 06:45:54 init message: Loading block index...
2016-07-03 06:45:54 Opening LevelDB in /home/bitcoin/.bitcoin/blocks/index
2016-07-03 06:45:54 IO error: /home/bitcoin/.bitcoin/blocks/index: Invalid argument
2016-07-03 06:45:54 : Error opening block database.

Do you want to rebuild the block database now?
: Error opening block database.

Do you want to rebuild the block database now?
2016-07-03 06:45:54 Aborted block database rebuild. Exiting.
2016-07-03 06:45:54 scheduler thread interrupt
2016-07-03 06:45:54 Shutdown: In progress...
2016-07-03 06:45:54 StopNode()
2016-07-03 06:45:54 Shutdown: done
root@dbf45

which I find a reference to here: boot2docker/boot2docker#794 so it seems there's a problem running bitcoind on VirtualBox (which I use for running docker on OSX)... however, curiously this is not the same error I get when I just run the container... a bit at a loss here...

@ruimarinho
Copy link
Owner

Indeed, this is related to how VirtualBox handles some file system calls. I honestly don't know the specifics but there's nothing we can do on the docker image side. Have you considered using Docker for Mac? It uses a custom file driver (osxfs) built specifically for Mac which does not present this issue.

@ekkis
Copy link
Author

ekkis commented Jul 5, 2016

I appreciate your writing back. I removed Boot2Docker and installed the new (beta) Docker for Mac but I'm still unable to run. if I manually log into the container and run the server like this:

$ docker run --rm -it --name bitcoind -p 8332 -v ${PWD}/bitcoind:/home/bitcoin/.bitcoin --entrypoint=/bin/bash seegno/bitcoind:latest
root@8ecc1262ff23:/# bitcoind -server -printtoconsole -datadir=/home/bitcoin/.bitcoin

it seems to work but running it from the host:

$ docker run --rm -it --name bitcoind -p 8332 -v ${PWD}/bitcoind:/home/bitcoin/.bitcoin seegno/bitcoind:latest -server -printtoconsole

fails with:

chown: changing ownership of '/home/bitcoin/.bitcoin/.cookie': Operation not permitted
chown: changing ownership of '/home/bitcoin/.bitcoin/.lock': Operation not permitted
chown: changing ownership of '/home/bitcoin/.bitcoin': Operation not permitted

can you spot what the issue might be? here's the directory I'm mounting:

$ls -alF bitcoind

drwx------ 4 ekkis staff 136 Jul 5 11:38 bitcoind/

@ekkis
Copy link
Author

ekkis commented Jul 5, 2016

I also had a look at what the original entry point does and tried running with an alternative directory but it too failed:

$ docker run --rm -it --name bitcoind -p 8332 -e BITCOIN_DATA=/data -v ${PWD}/bitcoind:/data seegno/bitcoind:latest -server -printtoconsole

/entrypoint.sh: assuming arguments for bitcoind
chown: changing ownership of '/data/.cookie': Operation not permitted
chown: changing ownership of '/data/.lock': Operation not permitted
chown: changing ownership of '/data': Operation not permitted

@ekkis
Copy link
Author

ekkis commented Jul 5, 2016

if I log into the container and run the entry point (since I replaced it in my invocation to the container), I get an error:

root@811e3f6c65b1:/# ./entrypoint.sh

./entrypoint.sh: 4: [: =: unexpected operator
./entrypoint.sh: 10: [: =: unexpected operator

and curiously this fails too:

root@811e3f6c65b1:/# /bin/sh
# if [ $(echo "$1" |cut -c1) = "-"]; then
> echo "ok"
> fi

/bin/sh: 1: [: missing ]

I don't get it

@ekkis
Copy link
Author

ekkis commented Jul 5, 2016

so the problem seems to be that if $1 is empty it needs to be written like this:

if [ "$(echo $1 |cut -c1)" = "-"]; then

but I see that entrypoint.sh is called without parameters in the Dockerfile, so I'm wondering why I see the message:

/entrypoint.sh: assuming arguments for bitcoind

in my penultimate message...

@ekkis
Copy link
Author

ekkis commented Jul 5, 2016

ah... I get it now. CMD ["bitcoind"] is actually a parameter call to the entry point, and now if I log into the container and run /entrypoint.sh "bitcoind" I get the error messages failing to change the ownership. now the question is why?

I presume the container runs under the docker host id, which wouldn't have permission to change ownership of my folder... so the question is: how do I enable the docker host to own it?

@ekkis
Copy link
Author

ekkis commented Jul 5, 2016

I've created a post on the docker site for this: https://forums.docker.com/t/failure-to-chown-a-directory-on-the-host/17445

...but in discussing this with some of the blokes on irc#docker it was suggested that the chown in the entry point should be removed...

@ekkis
Copy link
Author

ekkis commented Jul 5, 2016

final note: I killed all containers running, removed all volumes, all images, and ran the command again. it worked as it should. so I guess it was some bad juju from the times I was running with boot2docker. so we're all good now. thanks a bunch!

@ruimarinho
Copy link
Owner

Sorry for the lack of feedback here @ekkis, but I'm glad you're on track again!

@ekkis
Copy link
Author

ekkis commented Jul 15, 2016

yes, thank you for putting all this together. your efforts to maintain this make it child's play to put things together and saves those of us playing with this stuff a ton of work. cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants