I am working on building a high availability setup using keepalived, where each server will have its own set of dockers that will get handled appropriately depending on if it is in BACKUP or MASTER. However, for testing purposes, I don't have 2 boxes available that I can turn on and off for this. So, is there is a good (preferably lightweight) way I can setup multiple dockers with the same name on the same machine?
Essentially, it would like it to look something like this:
Physical Server A
-----------------------------------------
| Virtual Server A |
| -------------------------------------- |
| | keepalived - htmld - accessd - mysql |
| -------------------------------------- |
| ^ |
| | |
| v |
| Virtual Server B |
| -------------------------------------- |
| | keepalived - htmld - accessd - mysql |
| -------------------------------------- |
-----------------------------------------
Thanks
You cannot have multiple containers with the exact same name, but you can use
docker-composefile to have several directories and containers with same name (but with some differences that I explain below).You can read more about it in Docker Docs regarding my below explanation.
Let us suppose yours:
In your case, I would create two directories:
vsbandvsb. Now let's go into these two directories.We have these one file (at least, but you can have more per your requirement):
Note the file names exactly, as
Dockerfilestarts with capital D.Let's watch
docker-compose.yml:Let's dig into
docker-compose.ymlfirst:Versionpart defines which version to use.Servicespart starts the services and containers you want to create and run.I've used names like
keepalivedunderservices. You can use any name you want there, as it's your choice.Under
keepalived, the keywordbuildspecifies in which pathDockerfileexists, so that as the path is called/home/vsa/keepalived, so we use.which means here and then it goes tokeepaliveddirectory, searching forDockerfile(indocker-compose.ymlforvsb, it searches for this file in/home/vsb/keepalived).networkspart specifies theexternalnetwork these containers use, so that when all of our containers from docker-compose are running, then they're in the same docker network, so they can see and talk to each other.namepart has the namesome_networkthat you can choose any name you want that created before.How to create a network called
some_networkis, if you're in Linux, you should rundocker network create some_networkbefore running docker-compose file.volumespart specifies the name of volume of these services.And here is an example in
keepaliveddirectory for a file calledDockerfile:Now let's go to
Dockerfile:FROMcommand specifies which OS base to use. In this case, we want to useubuntufor example, so that we create our image based onubuntu.There are other commands you can see them all in above link.
After having finished both
Dockerfileanddocker-compose.ymlfiles with your own commands and keywords, you can run and create them by these commands:Now we'll have eight containers calling these (docker automatically called them, otherwise you explicitly name them on your own):