1 00:00:01,000 --> 00:00:04,490 ‫OK. 2 00:00:04,540 --> 00:00:09,190 ‫This is me running through assignment 2. I've got three panes open here. 3 00:00:09,220 --> 00:00:16,250 ‫I've got on my left where I can run the docker compose commands. You can see in this directory, 4 00:00:16,270 --> 00:00:21,270 ‫it's the same directory you're starting with. The readme that tells me how to get through it. 5 00:00:21,310 --> 00:00:26,020 ‫Then the Dockerfile that's empty and a docker compose file that's empty. 6 00:00:26,020 --> 00:00:33,130 ‫Then on my right, I've got Vim opened so that I can see my files I need to edit up top. Then 7 00:00:33,130 --> 00:00:34,900 ‫down below I have the instructions. 8 00:00:34,900 --> 00:00:38,890 ‫First, I need to focus on the Dockerfile. 9 00:00:38,920 --> 00:00:52,860 ‫It says I need to do a from drupal 8.2. Then I need to do a run to install Git. Apt get update. 10 00:00:53,700 --> 00:00:54,170 ‫update. 11 00:01:02,320 --> 00:01:05,910 ‫By the way, the install -y...the -y there 12 00:01:05,920 --> 00:01:07,840 ‫means automatically say yes. 13 00:01:07,880 --> 00:01:17,280 ‫And that way it'll auto...it won't prompt to install Git. 14 00:01:17,350 --> 00:01:19,220 ‫And this talks about some proper cleanup. 15 00:01:19,220 --> 00:01:24,150 ‫So any time you use apt-get, apt-get actually creates a cache when you do the apt-get update. 16 00:01:24,170 --> 00:01:28,880 ‫So we really want to delete that cache because it's at least 10MB taking up our image that we 17 00:01:28,880 --> 00:01:30,530 ‫don't need. 18 00:01:30,560 --> 00:01:40,280 ‫In this case, I can use the backslash, which means include the next line in this command. And then 19 00:01:40,280 --> 00:01:43,940 ‫the && symbols...or ampersand 20 00:01:43,960 --> 00:01:49,870 ‫ampersands... are telling me that if the first command succeeds, then also do this one. 21 00:01:49,890 --> 00:01:51,370 ‫And actually we have one right here. 22 00:01:51,380 --> 00:02:00,280 ‫So that's actually the third command I'm going to be doing. Remove these specific files. 23 00:02:02,030 --> 00:02:05,350 ‫That's a pretty common one. You see this in a whole lot of images. 24 00:02:05,470 --> 00:02:10,050 ‫I just add it to all of my images just to keep them clean. 25 00:02:10,080 --> 00:02:11,840 ‫It's not actually a requirement to make it function. 26 00:02:11,890 --> 00:02:15,470 ‫It's just there to keep it clean. 27 00:02:15,540 --> 00:02:23,450 ‫So we need to change the working directory for our template, or our themes. 28 00:02:28,610 --> 00:02:30,210 ‫Then we're going to need to do a clone. 29 00:02:30,220 --> 00:02:31,250 ‫I'm going to go ahead and... 30 00:02:35,630 --> 00:02:37,010 ‫...copy that and paste it. 31 00:02:47,870 --> 00:02:54,280 ‫If you're a Git person, you might see these are familiar. Git, obviously is pulling our...is cloning 32 00:02:54,280 --> 00:03:02,050 ‫this particular Git repository down that is a template. It's using a specific branch. It's using these 33 00:03:02,050 --> 00:03:09,220 ‫two variables, these two options here, that I've put in are there to tell it to only download the latest 34 00:03:09,220 --> 00:03:13,370 ‫copy and only that particular branch. It basically saves you a whole lot of time. 35 00:03:13,390 --> 00:03:20,200 ‫It actually saves you minutes on downloading Git repositories. If you only need the absolute latest commit, 36 00:03:20,230 --> 00:03:25,130 ‫and all the files in it, and you only need a particular branch which is probably all you need when you're 37 00:03:25,140 --> 00:03:26,480 ‫going to deploy an image. 38 00:03:26,590 --> 00:03:29,900 ‫Because if we were going to change that, we would just build a new image. Right? 39 00:03:29,920 --> 00:03:34,690 ‫So that's a good tip. 40 00:03:34,840 --> 00:03:40,510 ‫In case you're using Git a lot for image building, it saves you a lot of time and space really because 41 00:03:40,660 --> 00:03:44,980 ‫you don't need the whole history of the repository in there. You just need the latest commit. 42 00:03:45,400 --> 00:03:45,750 ‫OK. 43 00:03:45,760 --> 00:03:52,600 ‫Then the problem here is that these files...this is a common problem in Docker...that any commands you 44 00:03:52,600 --> 00:03:56,980 ‫run here, they're all going to run as root. 45 00:03:57,100 --> 00:04:02,360 ‫So these files were just downloaded and put in that directory as root. 46 00:04:02,410 --> 00:04:10,070 ‫But the problem is is that the Apache web server expects those files to be the www data user. 47 00:04:10,270 --> 00:04:17,890 ‫So I have to change the permissions afterward in order to make it work well. 48 00:04:18,010 --> 00:04:20,280 ‫You don't have to know these commands. 49 00:04:20,280 --> 00:04:27,780 ‫But this is a very common one shown, which stands for change owner. And -r means 50 00:04:27,810 --> 00:04:37,190 ‫all files, including subdirectories and subfiles, to this user and this group. 51 00:04:39,610 --> 00:04:42,200 ‫We'll confine it to just the directory we created. 52 00:04:44,050 --> 00:04:50,640 ‫Save us a couple of microseconds. I then need to change my working directory back just in case 53 00:04:50,660 --> 00:04:59,620 ‫the application expects to be in the working directory that it started in. 54 00:04:59,880 --> 00:05:04,710 ‫I don't need to specify any other, like a cmd or anything, because those are already specified in the 55 00:05:04,710 --> 00:05:05,460 ‫from image... 56 00:05:05,490 --> 00:05:15,340 ‫the Drupal image that I'm pulling from. All right. Think I'm done there. 57 00:05:15,870 --> 00:05:19,960 ‫Let's go to the Compose file. 58 00:05:20,260 --> 00:05:25,610 ‫If you kept your file before, it might look something like this. Right? 59 00:05:26,940 --> 00:05:35,240 ‫It has the services, and then it has the Drupal with the image name drupal, and then the volumes, and then 60 00:05:35,240 --> 00:05:38,240 ‫the postgres, and the environment variable for the password. 61 00:05:38,240 --> 00:05:40,220 ‫And then we define the volumes. 62 00:05:40,220 --> 00:05:47,780 ‫What we have to do to make this work in this situation, according to our instructions, 63 00:05:49,390 --> 00:05:52,560 ‫we need to rename the image. 64 00:05:52,630 --> 00:06:02,170 ‫Any time there is, in a compose file, an image key and a build key, it changes the purpose of the image 65 00:06:02,170 --> 00:06:03,190 ‫key. 66 00:06:03,250 --> 00:06:11,240 ‫Now instead of us telling it, 'hey, I want you to download the Drupal official image' we're saying, once 67 00:06:11,240 --> 00:06:21,650 ‫we add in the build, we're saying, 'hey, I want to build from a specific location on my local machine and 68 00:06:21,650 --> 00:06:25,320 ‫then I want to call the image you build this image name.' 69 00:06:25,400 --> 00:06:28,510 ‫Now, I don't actually have to specify the image name. 70 00:06:28,550 --> 00:06:34,250 ‫I could delete the image line altogether and it would actually create an automatically named name based 71 00:06:34,250 --> 00:06:39,050 ‫on the Compose naming, that you probably have noticed. Whenever you use Compose, it names everything to 72 00:06:39,050 --> 00:06:41,760 ‫be friendly to that particular project. 73 00:06:43,970 --> 00:06:50,330 ‫But, we're going to go ahead and hard code it in here. 74 00:06:50,660 --> 00:06:53,390 ‫Notice I'm putting in a dot for build. 75 00:06:53,420 --> 00:07:00,380 ‫That's just a shortcut, a shorthand for just saying, 'hey, just build in this directory and use the Dockerfile 76 00:07:00,390 --> 00:07:02,190 ‫that's the default name.' 77 00:07:02,480 --> 00:07:07,430 ‫I'm not giving it any build options. I'm not telling it a custom build file or custom location. 78 00:07:07,430 --> 00:07:11,060 ‫I'm just telling it the simplest way, which is how we built it. 79 00:07:11,080 --> 00:07:13,970 ‫All right. That's done. 80 00:07:14,010 --> 00:07:19,130 ‫That should build a custom image based on my Dockerfile. Then down here in postgres, I need to actually 81 00:07:19,190 --> 00:07:21,150 ‫put in a volume. 82 00:07:21,470 --> 00:07:25,190 ‫We want it to preserve our data. 83 00:07:25,700 --> 00:07:34,520 ‫The reason we want to preserve the data is if you're testing this, and you do a docker compose down, 84 00:07:34,520 --> 00:07:38,880 ‫it will actually delete the database and then we won't... 85 00:07:39,020 --> 00:07:44,540 ‫when we turn it back on, it won't have the data in there. So we want to ensure that we're keeping the 86 00:07:44,540 --> 00:07:48,750 ‫data across Compose restarts. 87 00:07:48,830 --> 00:07:53,030 ‫If we do a docker compose down now, after we have this data volume in there, it won't actually remove that 88 00:07:53,030 --> 00:08:11,110 ‫data volume, unless we do a -v on the end, which tells it, 'hey, I also want to delete the volumes.' 89 00:08:11,220 --> 00:08:12,200 ‫I think that's right. 90 00:08:12,200 --> 00:08:16,310 ‫Drupal data var lib postgres 91 00:08:19,960 --> 00:08:21,150 ‫SQL data. 92 00:08:21,170 --> 00:08:21,760 ‫All right. 93 00:08:21,960 --> 00:08:26,080 ‫Then I need to also put that down here. 94 00:08:26,100 --> 00:08:29,070 ‫Data. 95 00:08:29,130 --> 00:08:29,650 ‫All right. 96 00:08:29,650 --> 00:08:31,220 ‫I think we're ready. 97 00:08:32,440 --> 00:08:35,250 ‫Saving my files. 98 00:08:35,570 --> 00:08:48,650 ‫Let's see if we can do a docker compose up. OK, let's check our browser localhost 8080. 99 00:08:48,700 --> 00:08:49,620 ‫All right. 100 00:08:50,150 --> 00:08:54,350 ‫If this all worked, I can walk through this install like we did before 101 00:08:57,480 --> 00:09:01,700 ‫and postgres postgres 102 00:09:04,510 --> 00:09:05,110 ‫mypasswd 103 00:09:07,930 --> 00:09:15,950 ‫postgres. Save and continue. I'm going a little fast this time because I figure you've done it before. 104 00:09:23,410 --> 00:09:31,210 ‫I'm going to configure the site real quick. 105 00:09:37,750 --> 00:09:38,100 ‫OK. 106 00:09:38,120 --> 00:09:45,800 ‫We're on the site, and the instructions tell us to go to the appearance tab and notice we're on the 107 00:09:46,160 --> 00:09:48,400 ‫Bartik default. 108 00:09:48,440 --> 00:09:52,490 ‫We had this uninstalled theme down here that wouldn't have existed had we not installed it with 109 00:09:52,490 --> 00:09:53,840 ‫our image. 110 00:09:54,200 --> 00:09:56,500 ‫I can click install and set as default. 111 00:10:01,040 --> 00:10:02,470 ‫Then click back to site. 112 00:10:05,150 --> 00:10:11,150 ‫I have a totally new theme on my site using the bootstrap framework from Twitter which is a pretty 113 00:10:11,150 --> 00:10:11,810 ‫popular 114 00:10:15,690 --> 00:10:18,750 ‫templating system for CSS and websites. 115 00:10:18,750 --> 00:10:19,260 ‫So, 116 00:10:23,500 --> 00:10:24,790 ‫everything works as it should. 117 00:10:24,790 --> 00:10:32,840 ‫If I went back and actually stopped this, abort it, and then did a down, it's actually going to delete 118 00:10:32,840 --> 00:10:33,670 ‫the images. 119 00:10:33,680 --> 00:10:36,090 ‫But remember, it's not going to delete the data. 120 00:10:36,230 --> 00:10:44,480 ‫If I did a docker compose up again, what should happen is all those config files in the Drupal modules 121 00:10:44,480 --> 00:10:49,280 ‫and profiles, and sites, and themes, and then the data that's actually in the database, should all still 122 00:10:49,280 --> 00:10:50,580 ‫be there. 123 00:10:50,600 --> 00:10:54,270 ‫I should be able to hit refresh and it still works. 124 00:10:57,340 --> 00:11:05,280 ‫What's great about this way is that you can actually keep your images and your containers relatively 125 00:11:05,280 --> 00:11:06,140 ‫clean. 126 00:11:06,300 --> 00:11:11,310 ‫That way, when you're shifting between projects, you could technically get rid of that stuff and just 127 00:11:11,310 --> 00:11:17,010 ‫leave it alone...the volumes...the volumes alone...don't delete the data in them. Just leave the volumes 128 00:11:17,010 --> 00:11:18,690 ‫alone and don't delete their data. 129 00:11:18,840 --> 00:11:22,500 ‫Then when you come back to the project, you've already got all the sample data already in there and 130 00:11:22,500 --> 00:11:23,700 ‫you don't start from scratch. 131 00:11:25,230 --> 00:11:26,170 ‫All right. That's it.