‫All right Nuno's asking I need my docker file command to start Cassandra server and after that I need
‫to import a database schema.
‫What is the best way to do that.
‫So if someone hasn't already answered you in chat because sometimes that happens while I'm rambling
‫on the the entry point script is sort of the universal way to do things on container startup.
‫So this means that you have inside your Docker file you have the entry point and you have this BMD.
‫Now in my course Docker mastery I focus on the CMT because that's really the thing that you need to
‫understand to be at the beginning what I need to add is a section at least one lecture on the entry
‫point and discussing the various ways that you can do entry points.
‫So an entry point when we break it down the entry point in the CND are really two parts of the same
‫single line or single command that Docker runs when your container starts.
‫But the trick is is with the magic of bash scripting you can take the entry point and instead of it
‫just being the beginning of the command that might be on in front of the CMT it can run a script and
‫then at the end of that script you can tell it to pass execution to the rest of the command line.
‫So it may not make a whole lot of sense but let's go check a real world went out and see what we can
‫see so I'm going to pull up my sequel because really any persistent data storage system is going to
‫act the same way here
‫and if I look up on Docker Hub
‫so I'm at the Docker Hub my sequel official image.
‫And if I click on any one of these releases to top I will get the docker file which is open source and
‫in this file you'll find lots of things.
‫Obviously it's installing my sequel and getting sequel properly configured but down at the bottom you'll
‫notice a couple of things one is it's copying a shell script into a certain location and it's running
‫assembling there but that's just really for backwards compatibility.
‫But down here this is the key part the entry point script
‫which the entry point itself the command in the darker file doesn't have to be a script.
‫Again it's really just taking if the if it exists the entry point and they see OMD and it's just putting
‫them together and running them all in one line.
‫So you would see this the two common way as the entry point is used is either for the beginning of a
‫command that maybe if you're using Docker to run a command line utility I do this in 82 ping
‫see if I can uh so I have a github.
‫I have a Docker image rather and I get hub repo behind it and what it's doing is it's running a single
‫command line utility in a container.
‫And the way that it works here is I have the entry point being the command itself.
‫And then since the CMB goes after that when I have both of them in my Docker file it just switches them
‫together.
‫I have it running the default CRM D so if you think about it when I run this command from the command
‫I can do Docker run.
‫Brett Fisher slash HP paying.
‫And then I just hit enter and then it will automatically run the version command.
‫But if I keep typing in that command line right.
‫Tucker run.
‫Brett Fisher if I just do that it's gonna pull the image.
‫Whoops sorry let me uh switch screens on you
‫so if I run this image it's gonna run it by default and it basically dumps out the help because that's
‫what the docker file told it to do in the CRM D line.
‫But if I just change something on the end because remember the format of a docker run command is that
‫it will do Docker run and then do your options then do the image you're going to set you're going to
‫run and then anything after that replaces the CND in line.
‫So it's like a dynamic replacement of the CMT.
‫So if I just run here Google dot com it will replace the dash dash version that it would run by default.
‫So this is a really cool way that you can use Docker run as a command line utility and that's a good.
‫That's my example essentially of how to do that.
‫Now the other way to do it is with
‫is not that that's the that's the one way to do it the other way is a shell script so we'll see here
‫the entry point here is defining the file that it should run.
‫And then if I just scroll all the way to the top here and I do this eight point no directory I sort
‫of go up one directory I'll actually find it there's another file there.
‫That's the docker entry point script that it's copying in on the build.
‫Now in this script what's going on.
‫There's tons of stuff in here.
‫Probably at least a hundred lines.
‫Yep.
‫In fact it's hundreds of lines.
‫But the magic part here is this.
‫Zoom out.
‫Okay.
‫Go away scroll bar.
‫I do not want to see you.
‫Let's just go to Ras
‫that very bottom line there that.
‫Exactly.
‫And then the dollar sign at that tells the shell hey I'm ending this script please pass the execution
‫to the rest of my command line which would be whatever is in the CMT and in this case it was the my
‫sequel demon.
‫So essentially what's gonna happen when a container starts up in this case is it will run the script.
‫It gets to the end of the script the exact says Please do whatever else I told you at the end of this
‫command and that runs your demon.
‫You're you're my sequel demon in the foreground so that it stays running.
‫Now what the script does is all the things you probably didn't realize were happening in the background
‫when you started a database container.
‫It creates the default user that you want to set.
‫It changes the root password to whatever you want it to set.
‫It creates the database based on what you told it and it's doing all that and environment variables
‫right.
‫Because if we backed up to just duplicate this and if we backed up to the library
‫you know on most of these official images you're gonna have a whole bunch of environment variables and
‫it specifies them all down here.
‫And all those environment variables are used in that script to pre configure my sequel.
‫Now in the file itself if you were actually to dive into it it is setting some environment variables
‫and finding files in case you're using Drucker's warm secret stuff like that and then it's basically
‫getting every all the data it needs to configure it.
‫Then it starts up my sequel configured it including changing the root password in all the other things.
‫Then it shuts down my sequel and then ends the script and then passes that execution to my sequel to
‫start up again but this time for good.
‫So it's essentially starting sequel doing some things stopping sequels starting a backup.
‫And that's the way that all these work all these persistent storage systems inside of the official containers
‫work.
‫So for you The long answer to this question is that you're going to want to use it in your own custom
‫entrapment script maybe you copy the default one if there is one or maybe you make your own and then
‫you would make your own image that would then create that schema initially on the first startup.
‫Now once you have your fear a schema inside the database you know you're not going to really want to
‫update schemas that way you would want to do further schemas.
‫Through some other utility outside of that container right you would run your my cycle commands from
‫another container and then they would run over the network something like that.
‫Now you don't have to change this at all you could simply have it start up your Cassandra and then add
‫the schema from a remote from a different container but you would have to control that order right.
‫You would have to wait for Cassandra to start up.
‫You would have to have another container that maybe has its own script and then that script maybe a
‫smart enough to keep checking for Cassandra to see if it's ready.
‫And then when it's ready then run your schema either schema update or your original schema installation.
‫Essentially you could do it that way and that and a lot of cases is probably the right way to do it
‫but especially when you're doing local development or you just want to speed up something small and
‫easy and you just want to build a scheme of the first time and you wanted to do it automatically then
‫what you would do here is you would use the official default image and you would add your own schema
‫and file to that in your own custom image and essentially it would when it started up the first time
‫it would do that now.
‫Here's the problem and you gotta watch out for this this entry point script runs every time the container
‫starts at least from that image right from that image that you had built the custom one.
‫So you want to make sure that your script is smart enough that it doesn't rerun the schema over and
‫over again on an ad database it already has the schema.
‫So you have to build on that intelligence and that's why sometimes depending on your model if you're
‫thinking of updating things regularly or if you're constantly moving databases around in a swarm cluster
‫or Cuban ideas cluster then doing it inside the database container itself may not be the right strategy
‫for you but this option exists.
‫So check it out.
‫And that is like the Cliff Notes on what to do with entry points which was not in my original course
‫so I could probably say that this video in there and least have supplemental material for now that's
‫better than having nothing.