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