@@ -43,12 +43,14 @@ The first thing we need to do is create a `compose.yml` file.
4343All ` compose.yml ` files start with ` services: ` .
4444This is the root element under which we define the services we want to run.
4545``` yml
46+ # compose.yml
4647services :
4748` ` `
4849
4950Next, let's add the service for the SPUC container.
5051We'll call it ` spuc` and we will tell it what `image` to use.
5152` ` ` yml
53+ # compose.yml
5254services:
5355 spuc: # The name of the service
5456 image: spuacv/spuc:latest # The image to use
@@ -253,6 +255,7 @@ If you just want to stop it, you can use `[Ctrl+C]` like we did before.
253255The next item in our list is the name of the container.
254256We can name the container using the ` container_name ` key.
255257``` yml
258+ # compose.yml
256259services :
257260 spuc :
258261 image : spuacv/spuc:latest
@@ -298,6 +301,7 @@ It's worth noting the `ports` key is a list, so we can map multiple ports if we
298301and that the host and container ports don't have to be the same!
299302
300303``` yml
304+ # compose.yml
301305services :
302306 spuc :
303307 image : spuacv/spuc:latest
@@ -329,6 +333,7 @@ We will use a bind mount for this - mapping a file from the host to the containe
329333
330334As with the CLI, this is (confusingly) done using the ` volumes ` key.
331335``` yml
336+ # compose.yml
332337services :
333338 spuc :
334339 image : spuacv/spuc:latest
@@ -357,6 +362,7 @@ Otherwise, it generates a volume.
357362
358363Let's add a volume to persist the unicorn sightings between runs of the container.
359364``` yml
365+ # compose.yml
360366services :
361367 spuc :
362368 image : spuacv/spuc:latest
@@ -382,6 +388,7 @@ The volumes are separate from *services*, so they are declared at the same level
382388To declare a named volume, we specify its name and end with a ` : ` .
383389We will do this at the end of the file.
384390``` yml
391+ # compose.yml
385392services :
386393 spuc :
387394 image : spuacv/spuc:latest
@@ -436,6 +443,7 @@ Next, we need to set the `EXPORT` environment variable to `true`.
436443This is done using the ` environment ` key.
437444
438445``` yml
446+ # compose.yml
439447services :
440448 spuc :
441449 image : spuacv/spuc:latest
@@ -472,6 +480,7 @@ Finally, lets set the units by overriding the command, as we did before.
472480For this, we use the ` command ` key.
473481
474482``` yml
483+ # compose.yml
475484services :
476485 spuc :
477486 image : spuacv/spuc:latest
@@ -507,6 +516,7 @@ The only thing we are missing is enabling the plugin.
507516
508517We used a bind mount before to put the plugin file in the container, so lets try again:
509518``` yml
519+ # compose.yml
510520services :
511521 spuc :
512522 image : spuacv/spuc:latest
@@ -554,6 +564,7 @@ Let's go back to that.
554564
555565We could use the tag we used when we built the container to use that image:
556566``` yml
567+ # compose.yml
557568services :
558569 spuc :
559570 image : spuc-stats # Use the image we built earlier
@@ -578,6 +589,7 @@ Instead, we can use the `build` key to tell Docker Compose to build the containe
578589
579590To do that, we use the `build` key instead of the `image` key :
580591` ` ` yml
592+ # compose.yml
581593services:
582594 spuc:
583595 # image: spuc-stats
@@ -707,6 +719,7 @@ For our service named `spuc`, the hostname would be `spuc` with the protocol `ht
707719
708720Knowing this, we are able to add SPUCSVi to our Docker Compose file!
709721` ` ` yml
722+ # compose.yml
710723services:
711724 spuc:
712725 build:
@@ -821,6 +834,7 @@ This is a good security practice and helps keep things tidy.
821834
822835To do this we need to stop exposing the ports for SPUC, by removing the ` ports ` key from the SPUC service:
823836``` yml
837+ # compose.yml
824838services :
825839 spuc :
826840 build :
@@ -873,6 +887,7 @@ You also need to specify the network name for each service that you want to conn
873887For example, to specify the network name as ` spuc_network ` , you would add the following to the file:
874888
875889``` yml
890+ # compose.yml
876891services :
877892 spuc :
878893 build :
@@ -919,6 +934,7 @@ Docker Compose has a solution to this - the `depends_on` key.
919934
920935We can use this key to tell Docker Compose that the SPUCSVi service depends on the SPUC service.
921936` ` ` yml
937+ # compose.yml
922938services:
923939 spuc:
924940 build:
@@ -968,6 +984,7 @@ We need to add the `--fail` flag to `curl` to ensure that it returns a non-zero
968984The other change we need to make is to add a `condition` to the `depends_on` key in the SPUCSVi service.
969985This tells Docker Compose to only start the service if the service it depends on is *healthy*, rather than just *started*.
970986` ` ` yml
987+ # compose.yml
971988services:
972989 spuc:
973990 build:
@@ -1012,6 +1029,7 @@ This is a little hard to see in action as the SPUC service starts so quickly.
10121029To be able to see it, let's add a `sleep` command to the `entrypoint` of the SPUC service to simulate a slow start.
10131030
10141031` ` ` yml
1032+ # compose.yml
10151033services:
10161034 spuc:
10171035 build:
@@ -1068,6 +1086,7 @@ To simulate a service that does not pass the healthcheck,
10681086we can set the `EXPORT` environment variable to `false` in the SPUC service.
10691087This will mean that the export endpoint is not available, so the healthcheck will fail.
10701088` ` ` yml
1089+ # compose.yml
10711090services:
10721091 spuc:
10731092 build:
0 commit comments