mirror of
https://github.com/ilyakooo0/docker-hs.git
synced 2024-09-11 10:35:29 +03:00
Updates docs and examples
This commit is contained in:
parent
24070a0b39
commit
6dbf176f5b
@ -1,55 +1,64 @@
|
||||
import Docker.Client
|
||||
|
||||
runNginxContainer :: IO ContainerID
|
||||
runNginxContainer = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
|
||||
let pb = PortBinding 80 TCP [HostPort "0.0.0.0" 8000]
|
||||
let myCreateOpts = addPortBinding pb $ defaultCreateOpts "nginx:latest"
|
||||
cid <- createContainer myCreateOpts (Just "myNginxContainer")
|
||||
case cid of
|
||||
Left err -> error $ show err
|
||||
Right i -> do
|
||||
_ <- startContainer defaultStartOpts i
|
||||
return i
|
||||
runNginxContainer = do
|
||||
h <- defaultHttpHandler
|
||||
runDockerT (defaultClientOpts, h) $
|
||||
do let pb = PortBinding 80 TCP [HostPort "0.0.0.0" 8000]
|
||||
let myCreateOpts = addPortBinding pb $ defaultCreateOpts "nginx:latest"
|
||||
cid <- createContainer myCreateOpts (Just "myNginxContainer")
|
||||
case cid of
|
||||
Left err -> error $ show err
|
||||
Right i -> do
|
||||
_ <- startContainer defaultStartOpts i
|
||||
return i
|
||||
|
||||
stopNginxContainer :: ContainerID -> IO ()
|
||||
stopNginxContainer cid = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
|
||||
r <- stopContainer DefaultTimeout cid
|
||||
case r of
|
||||
Left _ -> error "I failed to stop the container"
|
||||
Right _ -> return ()
|
||||
stopNginxContainer cid = do
|
||||
h <- defaultHttpHandler
|
||||
runDockerT (defaultClientOpts, h) $
|
||||
do r <- stopContainer DefaultTimeout cid
|
||||
case r of
|
||||
Left _ -> error "I failed to stop the container"
|
||||
Right _ -> return ()
|
||||
|
||||
runPostgresContainer :: IO ContainerID
|
||||
runPostgresContainer = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
|
||||
let pb = PortBinding 5432 TCP [HostPort "0.0.0.0" 5432]
|
||||
let b = Bind "/tmp" "/tmp" Nothing
|
||||
let myCreateOpts = addBind b $ addPortBinding pb $ defaultCreateOpts "postgres:9.5"
|
||||
cid <- createContainer myCreateOpts Nothing
|
||||
case cid of
|
||||
Left err -> error $ show err
|
||||
Right i -> do
|
||||
_ <- startContainer defaultStartOpts i
|
||||
return i
|
||||
runPostgresContainer = do
|
||||
h <- defaultHttpHandler
|
||||
runDockerT (defaultClientOpts, h) $
|
||||
do let pb = PortBinding 5432 TCP [HostPort "0.0.0.0" 5432]
|
||||
let b = Bind "/tmp" "/tmp" Nothing
|
||||
let myCreateOpts = addBind b $ addPortBinding pb $ defaultCreateOpts "postgres:9.5"
|
||||
cid <- createContainer myCreateOpts Nothing
|
||||
case cid of
|
||||
Left err -> error $ show err
|
||||
Right i -> do
|
||||
_ <- startContainer defaultStartOpts i
|
||||
return i
|
||||
|
||||
-- | Example of how we can start a database container while hosting it's
|
||||
-- data in a data volume living inside another container.
|
||||
runPostgresWithDataContainer :: IO ContainerID
|
||||
runPostgresWithDataContainer = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
|
||||
-- We use a dummy command like /bin/true because we don't want to start
|
||||
-- the postgres database in the data container we just want it to
|
||||
-- create a container filesystem for us.
|
||||
let dataOpts = setCmd "/bin/true" $ defaultCreateOpts "postgres:9.5"
|
||||
cid <- createContainer dataOpts (Just "myDataContainer")
|
||||
_ <- case cid of
|
||||
Left err -> error $ show err
|
||||
Right i -> startContainer defaultStartOpts i
|
||||
let pb = PortBinding 5432 TCP [HostPort "0.0.0.0" 5432]
|
||||
-- Default permission is read-write if we don't specify anything
|
||||
let vf = VolumeFrom "myDataContainer" Nothing
|
||||
let myCreateOpts = addVolumeFrom vf $ addPortBinding pb $ defaultCreateOpts "postgres:9.5"
|
||||
ccid <- createContainer myCreateOpts (Just "pgContainer")
|
||||
case ccid of
|
||||
Left err -> error $ show err
|
||||
Right i -> do
|
||||
_ <- startContainer defaultStartOpts i
|
||||
return i
|
||||
runPostgresWithDataContainer = do
|
||||
h <- defaultHttpHandler
|
||||
runDockerT (defaultClientOpts, h) $
|
||||
-- We use a dummy command like /bin/true because we don't want to start
|
||||
-- the postgres database in the data container we just want it to
|
||||
-- create a container filesystem for us.
|
||||
do let dataOpts = setCmd "/bin/true" $ defaultCreateOpts "postgres:9.5"
|
||||
cid <- createContainer dataOpts (Just "myDataContainer")
|
||||
_ <-
|
||||
case cid of
|
||||
Left err -> error $ show err
|
||||
Right i -> startContainer defaultStartOpts i
|
||||
let pb = PortBinding 5432 TCP [HostPort "0.0.0.0" 5432]
|
||||
-- Default permission is read-write if we don't specify anything
|
||||
let vf = VolumeFrom "myDataContainer" Nothing
|
||||
let myCreateOpts = addVolumeFrom vf $ addPortBinding pb $ defaultCreateOpts "postgres:9.5"
|
||||
ccid <- createContainer myCreateOpts (Just "pgContainer")
|
||||
case ccid of
|
||||
Left err -> error $ show err
|
||||
Right i -> do
|
||||
_ <- startContainer defaultStartOpts i
|
||||
return i
|
||||
|
||||
|
@ -20,7 +20,9 @@ the host.
|
||||
import Docker.Client
|
||||
|
||||
runNginxContainer :: IO ContainerID
|
||||
runNginxContainer = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
|
||||
runNginxContainer = do
|
||||
h <- defaultHttpHandler
|
||||
runDockerT (defaultClientOpts, h) $ do
|
||||
let pb = PortBinding 80 TCP [HostPort "0.0.0.0" 8000]
|
||||
let myCreateOpts = addPortBinding pb $ defaultCreateOpts "nginx:latest"
|
||||
cid <- createContainer myCreateOpts
|
||||
@ -42,7 +44,9 @@ Let's stop the container now:
|
||||
|
||||
@
|
||||
stopNginxContainer :: ContainerID -> IO ()
|
||||
stopNginxContainer cid = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
|
||||
stopNginxContainer cid = do
|
||||
h <- defaultHttpHandler
|
||||
runDockerT (defaultClientOpts, h) $ do
|
||||
r <- stopContainer DefaultTimeout cid
|
||||
case r of
|
||||
Left err -> error "I failed to stop the container"
|
||||
@ -57,7 +61,9 @@ persist on the host file system.
|
||||
|
||||
@
|
||||
runPostgresContainer :: IO ContainerID
|
||||
runPostgresContainer = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
|
||||
runPostgresContainer = do
|
||||
h <- defaultHttpHandler
|
||||
runDockerT (defaultClientOpts, h) $ do
|
||||
let pb = PortBinding 5432 TCP [HostPort "0.0.0.0" 5432]
|
||||
let myCreateOpts = addBinds [Bind "\/tmp" "\/tmp" Nothing] $ addPortBinding pb $ defaultCreateOpts "postgres:9.5"
|
||||
cid <- createContainer myCreateOpts
|
||||
@ -70,7 +76,8 @@ runPostgresContainer = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
|
||||
|
||||
= Get Docker API Version
|
||||
|
||||
>>> runDockerT (defaultClientOpts, defaultHttpHandler) $ getDockerVersion
|
||||
>>> h <- defaultHttpHandler
|
||||
>>> runDockerT (defaultClientOpts, h) $ getDockerVersion
|
||||
Right (DockerVersion {version = "1.12.0", apiVersion = "1.24", gitCommit = "8eab29e", goVersion = "go1.6.3", os = "linux", arch = "amd64", kernelVersion = "4.6.0-1-amd64", buildTime = "2016-07-28T21:46:40.664812891+00:00"})
|
||||
|
||||
= Setup SSL Authentication
|
||||
|
Loading…
Reference in New Issue
Block a user