Skip to content

Instantly share code, notes, and snippets.

@ainoya
Created December 5, 2014 11:38
Show Gist options
  • Save ainoya/5a525ba8f639f4494811 to your computer and use it in GitHub Desktop.
Save ainoya/5a525ba8f639f4494811 to your computer and use it in GitHub Desktop.
lock while building image
# Build Docker image and run it as a container.
def up
begin
lock = File.open('/var/lock/subsys/pool.lock', 'w')
if lock.flock(File::LOCK_EX | File::LOCK_NB )
image_id = build
container_id = run image_id
confirm_running container_id
else
@logger.info("Locked! Other environment is under building process")
@logger.info("Please access after finishing another building process...")
end
rescue => ex
@logger.error ex
raise
ensure
@logger.close
lock.flock(File::LOCK_UN)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment