All right Nuno's asking I need my docker file command to start Cassandra server and after that I need 1
to import a database schema. 2
What is the best way to do that. 3
So if someone hasn't already answered you in chat because sometimes that happens while I'm rambling 4
on the the entry point script is sort of the universal way to do things on container startup. 5
So this means that you have inside your Docker file you have the entry point and you have this BMD. 6
Now in my course Docker mastery I focus on the CMT because that's really the thing that you need to 7
understand to be at the beginning what I need to add is a section at least one lecture on the entry 8
point and discussing the various ways that you can do entry points. 9
So an entry point when we break it down the entry point in the CND are really two parts of the same 10
single line or single command that Docker runs when your container starts. 11
But the trick is is with the magic of bash scripting you can take the entry point and instead of it 12
just being the beginning of the command that might be on in front of the CMT it can run a script and 13
then at the end of that script you can tell it to pass execution to the rest of the command line. 14
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 15
see so I'm going to pull up my sequel because really any persistent data storage system is going to 16
act the same way here 17
and if I look up on Docker Hub 18
so I'm at the Docker Hub my sequel official image. 19
And if I click on any one of these releases to top I will get the docker file which is open source and 20
in this file you'll find lots of things. 21
Obviously it's installing my sequel and getting sequel properly configured but down at the bottom you'll 22
notice a couple of things one is it's copying a shell script into a certain location and it's running 23
assembling there but that's just really for backwards compatibility. 24
But down here this is the key part the entry point script 25
which the entry point itself the command in the darker file doesn't have to be a script. 26
Again it's really just taking if the if it exists the entry point and they see OMD and it's just putting 27
them together and running them all in one line. 28
So you would see this the two common way as the entry point is used is either for the beginning of a 29
command that maybe if you're using Docker to run a command line utility I do this in 82 ping 30
see if I can uh so I have a github. 31
I have a Docker image rather and I get hub repo behind it and what it's doing is it's running a single 32
command line utility in a container. 33
And the way that it works here is I have the entry point being the command itself. 34
And then since the CMB goes after that when I have both of them in my Docker file it just switches them 35
together. 36
I have it running the default CRM D so if you think about it when I run this command from the command 37
I can do Docker run. 38
Brett Fisher slash HP paying. 39
And then I just hit enter and then it will automatically run the version command. 40
But if I keep typing in that command line right. 41
Tucker run. 42
Brett Fisher if I just do that it's gonna pull the image. 43
Whoops sorry let me uh switch screens on you 44
so if I run this image it's gonna run it by default and it basically dumps out the help because that's 45
what the docker file told it to do in the CRM D line. 46
But if I just change something on the end because remember the format of a docker run command is that 47
it will do Docker run and then do your options then do the image you're going to set you're going to 48
run and then anything after that replaces the CND in line. 49
So it's like a dynamic replacement of the CMT. 50
So if I just run here Google dot com it will replace the dash dash version that it would run by default. 51
So this is a really cool way that you can use Docker run as a command line utility and that's a good. 52
That's my example essentially of how to do that. 53
Now the other way to do it is with 54
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 55
the entry point here is defining the file that it should run. 56
And then if I just scroll all the way to the top here and I do this eight point no directory I sort 57
of go up one directory I'll actually find it there's another file there. 58
That's the docker entry point script that it's copying in on the build. 59
Now in this script what's going on. 60
There's tons of stuff in here. 61
Probably at least a hundred lines. 62
Yep. 63
In fact it's hundreds of lines. 64
But the magic part here is this. 65
Zoom out. 66
Okay. 67
Go away scroll bar. 68
I do not want to see you. 69
Let's just go to Ras 70
that very bottom line there that. 71
Exactly. 72
And then the dollar sign at that tells the shell hey I'm ending this script please pass the execution 73
to the rest of my command line which would be whatever is in the CMT and in this case it was the my 74
sequel demon. 75
So essentially what's gonna happen when a container starts up in this case is it will run the script. 76
It gets to the end of the script the exact says Please do whatever else I told you at the end of this 77
command and that runs your demon. 78
You're you're my sequel demon in the foreground so that it stays running. 79
Now what the script does is all the things you probably didn't realize were happening in the background 80
when you started a database container. 81
It creates the default user that you want to set. 82
It changes the root password to whatever you want it to set. 83
It creates the database based on what you told it and it's doing all that and environment variables 84
right. 85
Because if we backed up to just duplicate this and if we backed up to the library 86
you know on most of these official images you're gonna have a whole bunch of environment variables and 87
it specifies them all down here. 88
And all those environment variables are used in that script to pre configure my sequel. 89
Now in the file itself if you were actually to dive into it it is setting some environment variables 90
and finding files in case you're using Drucker's warm secret stuff like that and then it's basically 91
getting every all the data it needs to configure it. 92
Then it starts up my sequel configured it including changing the root password in all the other things. 93
Then it shuts down my sequel and then ends the script and then passes that execution to my sequel to 94
start up again but this time for good. 95
So it's essentially starting sequel doing some things stopping sequels starting a backup. 96
And that's the way that all these work all these persistent storage systems inside of the official containers 97
work. 98
So for you The long answer to this question is that you're going to want to use it in your own custom 99
entrapment script maybe you copy the default one if there is one or maybe you make your own and then 100
you would make your own image that would then create that schema initially on the first startup. 101
Now once you have your fear a schema inside the database you know you're not going to really want to 102
update schemas that way you would want to do further schemas. 103
Through some other utility outside of that container right you would run your my cycle commands from 104
another container and then they would run over the network something like that. 105
Now you don't have to change this at all you could simply have it start up your Cassandra and then add 106
the schema from a remote from a different container but you would have to control that order right. 107
You would have to wait for Cassandra to start up. 108
You would have to have another container that maybe has its own script and then that script maybe a 109
smart enough to keep checking for Cassandra to see if it's ready. 110
And then when it's ready then run your schema either schema update or your original schema installation. 111
Essentially you could do it that way and that and a lot of cases is probably the right way to do it 112
but especially when you're doing local development or you just want to speed up something small and 113
easy and you just want to build a scheme of the first time and you wanted to do it automatically then 114
what you would do here is you would use the official default image and you would add your own schema 115
and file to that in your own custom image and essentially it would when it started up the first time 116
it would do that now. 117
Here's the problem and you gotta watch out for this this entry point script runs every time the container 118
starts at least from that image right from that image that you had built the custom one. 119
So you want to make sure that your script is smart enough that it doesn't rerun the schema over and 120
over again on an ad database it already has the schema. 121
So you have to build on that intelligence and that's why sometimes depending on your model if you're 122
thinking of updating things regularly or if you're constantly moving databases around in a swarm cluster 123
or Cuban ideas cluster then doing it inside the database container itself may not be the right strategy 124
for you but this option exists. 125
So check it out. 126
And that is like the Cliff Notes on what to do with entry points which was not in my original course 127
so I could probably say that this video in there and least have supplemental material for now that's 128
better than having nothing.