This lesson is part of the Ignition with Docker course. You can browse the rest of the lessons below.


Autoplay Off


In this lesson, we'll take backups of our gateways and mount them into our containers so that we can restore them on startup.



(open in window)

[00:00] So far, we've created a Docker Compose app that mimics our theoretical production environment and we're ready to make some changes and start testing. However, there's one issue with our current setup. If we were to stop these containers and remove the named volumes or if we wanted to share this to the co-worker our gateway, database, and SMTP connections would need to be rebuilt. In this lesson we'll fix this issue with gateway backups and a new type of volume. First we're gonna need some gateway backups to preserve our gateway changes. We'll grab one from our frontend gateway. And then grab another from our backend gateway. What we want to do is make sure that these backups are available to our containers when they first start up and we can accomplish this with bind mounts. In the past, we've used named volumes which are created and managed by the Docker Engine and live somewhere on the host OS. Bind mounts are different in that we're taking a file or directory from our host OS and mounting it into the container.

[01:03] We can use this to mount our gateway backups into the gateway containers and then they can use them for automatic restores. Let's start with a little bit of prep work and let's make a new directory called "gw-init" in our project folder and that will stand for gateway initialization. Next thing we can do is take our gateway backups that we just grabbed and drop them into the new directory we made and I'm going to do this off screen. And as you can see, they're now in the "gw-init" folder. Let's rename these really quick so that we can more easily reference them. Let's name them "frontend.gwbk" and "backend.gwbk". Now we should have our two gateway backups in our folder and we can start creating the bind mounts. Add another volume to the frontend gateway and the syntax will be as follows. First we'll specify the file or directory on the host OS so this will be "." for the current working directory, "/ gw-init/frontend .gwbk".

[02:05] Next add a colon and then where this will go in the container. For that we can add "/restore.gwbk". Now we need to add another runtime argument, "-r", that will point to a gateway backup that should be restored on startup. Now, let's replicate the same steps for the backend gateway. We can copy and paste the bind mount. Change "frontend" to "backend". And then we'll copy and paste the restore command. Alright now we have our gateway backups, but the second thing we need to do is grab the files that are needed for gateway network connections. And those are the "uuid" and the "metro keystore". You don't have to follow along with this part, but I'll quickly show you where these files are in the container.

[03:02] I'm going to start a bash terminal in the frontend gateway. And the first file will be here in the "data" folder. And then the second one is in the "local" folder. We can start by copying these files from the containers to our host machine with "docker compose cp". We need to specify the service. Add a colon then the file we want, "usr/ local/bin/ignition/data/.uuid". Then a space and where we want it on the host machine which will be our "gw-init" folder and then we'll name this "frontend-uuid.txt". To speed this up hit the up arrow on your keyboard and then change the two places where it says "frontend" to "backend". Now we should have our gwbks and uuids for both gateways.

[04:03] Next we'll just need to grab the metro keystores and we'll do that with the same technique. We can hit the up arrow and instead of pointing to the uuid. This will be "local/metro-keystore". And that will become "backend-metro-keystore" in the "gw-init" folder. Once again hit up and then change "backend" to "frontend". Now we should have the gwbks, the uuids, and the metro-keystores for both gateways. So six files in total. Let's add the remainder of our bind mounts. The frontend gateway will get a new volume that takes our host frontend uuid file and mounts it to the proper location in the container. And then it will get one more that takes our host frontend metro- keystore file and mounts it in the container.

[05:13] We can copy both of these lines and paste them into the backend volumes below. And then we just need to change the "frontend" text to "backend". We should have everything we need and now we can save our compose file. Let's first run "docker compose down -v" and this is going to stop our containers and remove their volumes. Now we can type "docker compose up" and this will start up the containers as if they're starting for the first time. Let's log into our backend gateway and test whether or not our connections have been preserved. On the status page we can see that we have a database connection and a gateway network connection. And when we go into email settings there's our SMTP profile.

[06:06] Now that we've added our Gateway states to startup we could potentially zip up this project directory we've been working out of and if we loaded it onto another machine or sent it to a co-worker, these gateways would start up with valid connections to each item in our architecture. With that we can end this set of lessons on building out our testing environment. In the description for this video, you can find a link to this compose stack. That way, if you lose yours, then you can come back and download it there as a reference. I suggest continuing to play with this environment on your own and try adding some additional functionality as that's a great way to continue learning. Check out the videos in the next topic if you'd like to see more examples of Ignition with Docker.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.