janeczku / docker-machine-vultr

:m: Docker Machine driver for Vultr Cloud
MIT License
192 stars 25 forks source link

I often received "Could not get lock /var/lib/dpkg/lock" error while creating docker host #17

Closed twang2218 closed 7 years ago

twang2218 commented 7 years ago

Here is the log:

ζ docker-machine create -d vultr v1                                                              [0099b16]
Running pre-create checks...
(v1) Validating Vultr VPS parameters...
(v1) getting client
(v1) getting client
(v1) getting client
Creating machine...
(v1) getting client
(v1) Creating Vultr VPS...
(v1) getting client
(v1) Waiting for IP address to become available...
(v1) Created Vultr VPS ID: 6140199, Public IP: 45.32.130.69, Private IP:
Waiting for machine to be running, this may take a few minutes...
(v1) getting client
(v1) getting client
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with ubuntu(systemd)...
Error creating machine: Error running provisioning: ssh command error:
command : sudo apt-get update
err     : exit status 100
output  : Hit:1 http://security.ubuntu.com/ubuntu xenial-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease
Hit:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

As you can see, the sudo apt-get update command cannot execute as there is another apt-get running in the background, maybe because the system setup script running for the first time.

I think we should wait for a little longer or wait until the other apt exit.

geneticgrabbag commented 7 years ago

Confirming the same for me:

docker-machine create --driver vultr --vultr-api-key=$VULTR_TOKEN --vultr-region-id=2 --vultr-plan-id=29 --vultr-os-id=215 example.com

Running pre-create checks...
(example.com) Validating Vultr VPS parameters...
Creating machine...
(example.com) Creating Vultr VPS...
(example.com) Waiting for IP address to become available...
(example.com) Created Vultr VPS ID: 6342286, Public IP: 45.63.79.223, Private IP:
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with ubuntu(systemd)...
Error creating machine: Error running provisioning: Something went wrong running an SSH command!
command : sudo apt-get update
err     : exit status 100
output  : Reading package lists...
E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/
lvnilesh commented 7 years ago

This is happening because vultr runs update scripts once you instantiate. They should not be doing this. Please create a support case and ask them to:

  1. provide updated images
  2. leave the tasks of updating to users after users instantiate a machine
janeczku commented 7 years ago

Known issue. I wished Vultr wouldn't do that stuff. Might be worth bringing this up with the Docker Machine devs though.

janeczku commented 7 years ago

Thoughts, @gsmaul ?

gsmaul commented 7 years ago

@lvnilesh - that's only partially true. All Vultr operating system images are configured not to run system updates upon deployment. We refresh our images often so that they get updated packages, but this doesn't happen at deploy time.

However, Ubuntu 16.04 and 16.10 has an "apt-daily.service" that runs after the VM is booted, which causes the apt lock errors you're seeing. We considered disabling it on Vultr, but that system is part of Ubuntu and performs OS related tasks. We didn't want to open up new security issues and possible upgrade problems, so we left it alone. Our goal is to provide basically as close to the upstream installation as possible, with just a few minor changes to get the Vultr features (like custom hostname) working.

There's some more discussion on it here: http://unix.stackexchange.com/questions/315502/how-to-disable-apt-daily-service-on-ubuntu-cloud-vm-image

janeczku commented 7 years ago

@twang2218, there is a fix for the apt-get locking in docker-machine v0.9.0. https://github.com/docker/machine/pull/3891

Please re-open this ticket if upgrading does not fix it for you.

dtitov commented 6 years ago

Hi. I'm facing the same issue with Mac OS, Docker 17.06.2-ce, docker-machine version 0.12.2.