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
|
import Docker.Client
|
||||||
|
|
||||||
runNginxContainer :: IO ContainerID
|
runNginxContainer :: IO ContainerID
|
||||||
runNginxContainer = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
|
runNginxContainer = do
|
||||||
let pb = PortBinding 80 TCP [HostPort "0.0.0.0" 8000]
|
h <- defaultHttpHandler
|
||||||
let myCreateOpts = addPortBinding pb $ defaultCreateOpts "nginx:latest"
|
runDockerT (defaultClientOpts, h) $
|
||||||
cid <- createContainer myCreateOpts (Just "myNginxContainer")
|
do let pb = PortBinding 80 TCP [HostPort "0.0.0.0" 8000]
|
||||||
case cid of
|
let myCreateOpts = addPortBinding pb $ defaultCreateOpts "nginx:latest"
|
||||||
Left err -> error $ show err
|
cid <- createContainer myCreateOpts (Just "myNginxContainer")
|
||||||
Right i -> do
|
case cid of
|
||||||
_ <- startContainer defaultStartOpts i
|
Left err -> error $ show err
|
||||||
return i
|
Right i -> do
|
||||||
|
_ <- startContainer defaultStartOpts i
|
||||||
|
return i
|
||||||
|
|
||||||
stopNginxContainer :: ContainerID -> IO ()
|
stopNginxContainer :: ContainerID -> IO ()
|
||||||
stopNginxContainer cid = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
|
stopNginxContainer cid = do
|
||||||
r <- stopContainer DefaultTimeout cid
|
h <- defaultHttpHandler
|
||||||
case r of
|
runDockerT (defaultClientOpts, h) $
|
||||||
Left _ -> error "I failed to stop the container"
|
do r <- stopContainer DefaultTimeout cid
|
||||||
Right _ -> return ()
|
case r of
|
||||||
|
Left _ -> error "I failed to stop the container"
|
||||||
|
Right _ -> return ()
|
||||||
|
|
||||||
runPostgresContainer :: IO ContainerID
|
runPostgresContainer :: IO ContainerID
|
||||||
runPostgresContainer = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
|
runPostgresContainer = do
|
||||||
let pb = PortBinding 5432 TCP [HostPort "0.0.0.0" 5432]
|
h <- defaultHttpHandler
|
||||||
let b = Bind "/tmp" "/tmp" Nothing
|
runDockerT (defaultClientOpts, h) $
|
||||||
let myCreateOpts = addBind b $ addPortBinding pb $ defaultCreateOpts "postgres:9.5"
|
do let pb = PortBinding 5432 TCP [HostPort "0.0.0.0" 5432]
|
||||||
cid <- createContainer myCreateOpts Nothing
|
let b = Bind "/tmp" "/tmp" Nothing
|
||||||
case cid of
|
let myCreateOpts = addBind b $ addPortBinding pb $ defaultCreateOpts "postgres:9.5"
|
||||||
Left err -> error $ show err
|
cid <- createContainer myCreateOpts Nothing
|
||||||
Right i -> do
|
case cid of
|
||||||
_ <- startContainer defaultStartOpts i
|
Left err -> error $ show err
|
||||||
return i
|
Right i -> do
|
||||||
|
_ <- startContainer defaultStartOpts i
|
||||||
|
return i
|
||||||
|
|
||||||
-- | Example of how we can start a database container while hosting it's
|
-- | Example of how we can start a database container while hosting it's
|
||||||
-- data in a data volume living inside another container.
|
-- data in a data volume living inside another container.
|
||||||
runPostgresWithDataContainer :: IO ContainerID
|
runPostgresWithDataContainer :: IO ContainerID
|
||||||
runPostgresWithDataContainer = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
|
runPostgresWithDataContainer = do
|
||||||
-- We use a dummy command like /bin/true because we don't want to start
|
h <- defaultHttpHandler
|
||||||
-- the postgres database in the data container we just want it to
|
runDockerT (defaultClientOpts, h) $
|
||||||
-- create a container filesystem for us.
|
-- We use a dummy command like /bin/true because we don't want to start
|
||||||
let dataOpts = setCmd "/bin/true" $ defaultCreateOpts "postgres:9.5"
|
-- the postgres database in the data container we just want it to
|
||||||
cid <- createContainer dataOpts (Just "myDataContainer")
|
-- create a container filesystem for us.
|
||||||
_ <- case cid of
|
do let dataOpts = setCmd "/bin/true" $ defaultCreateOpts "postgres:9.5"
|
||||||
Left err -> error $ show err
|
cid <- createContainer dataOpts (Just "myDataContainer")
|
||||||
Right i -> startContainer defaultStartOpts i
|
_ <-
|
||||||
let pb = PortBinding 5432 TCP [HostPort "0.0.0.0" 5432]
|
case cid of
|
||||||
-- Default permission is read-write if we don't specify anything
|
Left err -> error $ show err
|
||||||
let vf = VolumeFrom "myDataContainer" Nothing
|
Right i -> startContainer defaultStartOpts i
|
||||||
let myCreateOpts = addVolumeFrom vf $ addPortBinding pb $ defaultCreateOpts "postgres:9.5"
|
let pb = PortBinding 5432 TCP [HostPort "0.0.0.0" 5432]
|
||||||
ccid <- createContainer myCreateOpts (Just "pgContainer")
|
-- Default permission is read-write if we don't specify anything
|
||||||
case ccid of
|
let vf = VolumeFrom "myDataContainer" Nothing
|
||||||
Left err -> error $ show err
|
let myCreateOpts = addVolumeFrom vf $ addPortBinding pb $ defaultCreateOpts "postgres:9.5"
|
||||||
Right i -> do
|
ccid <- createContainer myCreateOpts (Just "pgContainer")
|
||||||
_ <- startContainer defaultStartOpts i
|
case ccid of
|
||||||
return i
|
Left err -> error $ show err
|
||||||
|
Right i -> do
|
||||||
|
_ <- startContainer defaultStartOpts i
|
||||||
|
return i
|
||||||
|
|
||||||
|
@ -20,7 +20,9 @@ the host.
|
|||||||
import Docker.Client
|
import Docker.Client
|
||||||
|
|
||||||
runNginxContainer :: IO ContainerID
|
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 pb = PortBinding 80 TCP [HostPort "0.0.0.0" 8000]
|
||||||
let myCreateOpts = addPortBinding pb $ defaultCreateOpts "nginx:latest"
|
let myCreateOpts = addPortBinding pb $ defaultCreateOpts "nginx:latest"
|
||||||
cid <- createContainer myCreateOpts
|
cid <- createContainer myCreateOpts
|
||||||
@ -42,7 +44,9 @@ Let's stop the container now:
|
|||||||
|
|
||||||
@
|
@
|
||||||
stopNginxContainer :: ContainerID -> IO ()
|
stopNginxContainer :: ContainerID -> IO ()
|
||||||
stopNginxContainer cid = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
|
stopNginxContainer cid = do
|
||||||
|
h <- defaultHttpHandler
|
||||||
|
runDockerT (defaultClientOpts, h) $ do
|
||||||
r <- stopContainer DefaultTimeout cid
|
r <- stopContainer DefaultTimeout cid
|
||||||
case r of
|
case r of
|
||||||
Left err -> error "I failed to stop the container"
|
Left err -> error "I failed to stop the container"
|
||||||
@ -57,7 +61,9 @@ persist on the host file system.
|
|||||||
|
|
||||||
@
|
@
|
||||||
runPostgresContainer :: IO ContainerID
|
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 pb = PortBinding 5432 TCP [HostPort "0.0.0.0" 5432]
|
||||||
let myCreateOpts = addBinds [Bind "\/tmp" "\/tmp" Nothing] $ addPortBinding pb $ defaultCreateOpts "postgres:9.5"
|
let myCreateOpts = addBinds [Bind "\/tmp" "\/tmp" Nothing] $ addPortBinding pb $ defaultCreateOpts "postgres:9.5"
|
||||||
cid <- createContainer myCreateOpts
|
cid <- createContainer myCreateOpts
|
||||||
@ -70,7 +76,8 @@ runPostgresContainer = runDockerT (defaultClientOpts, defaultHttpHandler) $ do
|
|||||||
|
|
||||||
= Get Docker API Version
|
= 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"})
|
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
|
= Setup SSL Authentication
|
||||||
|
Loading…
Reference in New Issue
Block a user