Docker: Avoid committing container every time it's started up.

This was using a lot of disk space. Instead, start the container, and then
use the running container to check if docker is running it with the right
params. In the unlikely case that the params have changed, we still need to
commit the container and restart it. The common case of eg a reboot no
longer commits though.
This commit is contained in:
Joey Hess 2014-10-10 13:45:43 -04:00
parent 0a34736d6a
commit df0c0e56cb
2 changed files with 23 additions and 13 deletions

1
debian/changelog vendored
View File

@ -9,6 +9,7 @@ propellor (0.9.0) unstable; urgency=medium
immediate upgrades to the next stable release. immediate upgrades to the next stable release.
* debCdn switched from cdn.debian.net to http.debian.net, which seems to be * debCdn switched from cdn.debian.net to http.debian.net, which seems to be
better managed now. better managed now.
* Docker: Avoid committing container every time it's started up.
-- Joey Hess <joeyh@debian.org> Fri, 10 Oct 2014 11:37:45 -0400 -- Joey Hess <joeyh@debian.org> Fri, 10 Oct 2014 11:37:45 -0400

View File

@ -314,27 +314,33 @@ runningContainer :: ContainerId -> Image -> [RunParam] -> Property
runningContainer cid@(ContainerId hn cn) image runps = containerDesc cid $ property "running" $ do runningContainer cid@(ContainerId hn cn) image runps = containerDesc cid $ property "running" $ do
l <- liftIO $ listContainers RunningContainers l <- liftIO $ listContainers RunningContainers
if cid `elem` l if cid `elem` l
then do then checkident
-- Check if the ident has changed; if so the
-- parameters of the container differ and it must
-- be restarted.
runningident <- liftIO $ getrunningident
if runningident == Just ident
then noChange
else do
liftIO $ print ("runningident", runningident, "vs", ident)
void $ liftIO $ stopContainer cid
restartcontainer
else ifM (liftIO $ elem cid <$> listContainers AllContainers) else ifM (liftIO $ elem cid <$> listContainers AllContainers)
( restartcontainer ( do
-- The container exists, but is not
-- running. Its parameters may have
-- changed, but we cannot tell without
-- starting it up first.
void $ liftIO $ startContainer cid
checkident
, go image , go image
) )
where where
ident = ContainerIdent image hn cn runps ident = ContainerIdent image hn cn runps
-- Check if the ident has changed; if so the
-- parameters of the container differ and it must
-- be restarted.
checkident = do
runningident <- liftIO $ getrunningident
if runningident == Just ident
then noChange
else do
void $ liftIO $ stopContainer cid
restartcontainer
restartcontainer = do restartcontainer = do
oldimage <- liftIO $ fromMaybe image <$> commitContainer cid oldimage <- liftIO $ fromMaybe image <$> commitContainer cid
liftIO $ print ("restarting", oldimage)
void $ liftIO $ removeContainer cid void $ liftIO $ removeContainer cid
go oldimage go oldimage
@ -435,6 +441,9 @@ provisionContainer cid = containerDesc cid $ property "provisioned" $ liftIO $ d
stopContainer :: ContainerId -> IO Bool stopContainer :: ContainerId -> IO Bool
stopContainer cid = boolSystem dockercmd [Param "stop", Param $ fromContainerId cid ] stopContainer cid = boolSystem dockercmd [Param "stop", Param $ fromContainerId cid ]
startContainer :: ContainerId -> IO Bool
startContainer cid = boolSystem dockercmd [Param "start", Param $ fromContainerId cid ]
stoppedContainer :: ContainerId -> Property stoppedContainer :: ContainerId -> Property
stoppedContainer cid = containerDesc cid $ property desc $ stoppedContainer cid = containerDesc cid $ property desc $
ifM (liftIO $ elem cid <$> listContainers RunningContainers) ifM (liftIO $ elem cid <$> listContainers RunningContainers)