‫OK.
‫This is me running through assignment 2. I've got three panes open here.
‫I've got on my left where I can run the docker compose commands. You can see in this directory,
‫it's the same directory you're starting with. The readme that tells me how to get through it.
‫Then the Dockerfile that's empty and a docker compose file that's empty.
‫Then on my right, I've got Vim opened so that I can see my files I need to edit up top. Then
‫down below I have the instructions.
‫First, I need to focus on the Dockerfile.
‫It says I need to do a from drupal 8.2. Then I need to do a run to install Git. Apt get update.
‫update.
‫By the way, the install -y...the -y there
‫means automatically say yes.
‫And that way it'll auto...it won't prompt to install Git.
‫And this talks about some proper cleanup.
‫So any time you use apt-get, apt-get actually creates a cache when you do the apt-get update.
‫So we really want to delete that cache because it's at least 10MB taking up our image that we
‫don't need.
‫In this case, I can use the backslash, which means include the next line in this command. And then
‫the && symbols...or ampersand
‫ampersands... are telling me that if the first command succeeds, then also do this one.
‫And actually we have one right here.
‫So that's actually the third command I'm going to be doing. Remove these specific files.
‫That's a pretty common one. You see this in a whole lot of images.
‫I just add it to all of my images just to keep them clean.
‫It's not actually a requirement to make it function.
‫It's just there to keep it clean.
‫So we need to change the working directory for our template, or our themes.
‫Then we're going to need to do a clone.
‫I'm going to go ahead and...
‫...copy that and paste it.
‫If you're a Git person, you might see these are familiar. Git, obviously is pulling our...is cloning
‫this particular Git repository down that is a template. It's using a specific branch. It's using these
‫two variables, these two options here, that I've put in are there to tell it to only download the latest
‫copy and only that particular branch. It basically saves you a whole lot of time.
‫It actually saves you minutes on downloading Git repositories. If you only need the absolute latest commit,
‫and all the files in it, and you only need a particular branch which is probably all you need when you're
‫going to deploy an image.
‫Because if we were going to change that, we would just build a new image. Right?
‫So that's a good tip.
‫In case you're using Git a lot for image building, it saves you a lot of time and space really because
‫you don't need the whole history of the repository in there. You just need the latest commit.
‫OK.
‫Then the problem here is that these files...this is a common problem in Docker...that any commands you
‫run here, they're all going to run as root.
‫So these files were just downloaded and put in that directory as root.
‫But the problem is is that the Apache web server expects those files to be the www data user.
‫So I have to change the permissions afterward in order to make it work well.
‫You don't have to know these commands.
‫But this is a very common one shown, which stands for change owner. And -r means
‫all files, including subdirectories and subfiles, to this user and this group.
‫We'll confine it to just the directory we created.
‫Save us a couple of microseconds. I then need to change my working directory back just in case
‫the application expects to be in the working directory that it started in.
‫I don't need to specify any other, like a cmd or anything, because those are already specified in the
‫from image...
‫the Drupal image that I'm pulling from. All right. Think I'm done there.
‫Let's go to the Compose file.
‫If you kept your file before, it might look something like this. Right?
‫It has the services, and then it has the Drupal with the image name drupal, and then the volumes, and then
‫the postgres, and the environment variable for the password.
‫And then we define the volumes.
‫What we have to do to make this work in this situation, according to our instructions,
‫we need to rename the image.
‫Any time there is, in a compose file, an image key and a build key, it changes the purpose of the image
‫key.
‫Now instead of us telling it, 'hey, I want you to download the Drupal official image' we're saying, once
‫we add in the build, we're saying, 'hey, I want to build from a specific location on my local machine and
‫then I want to call the image you build this image name.'
‫Now, I don't actually have to specify the image name.
‫I could delete the image line altogether and it would actually create an automatically named name based
‫on the Compose naming, that you probably have noticed. Whenever you use Compose, it names everything to
‫be friendly to that particular project.
‫But, we're going to go ahead and hard code it in here.
‫Notice I'm putting in a dot for build.
‫That's just a shortcut, a shorthand for just saying, 'hey, just build in this directory and use the Dockerfile
‫that's the default name.'
‫I'm not giving it any build options. I'm not telling it a custom build file or custom location.
‫I'm just telling it the simplest way, which is how we built it.
‫All right. That's done.
‫That should build a custom image based on my Dockerfile. Then down here in postgres, I need to actually
‫put in a volume.
‫We want it to preserve our data.
‫The reason we want to preserve the data is if you're testing this, and you do a docker compose down,
‫it will actually delete the database and then we won't...
‫when we turn it back on, it won't have the data in there. So we want to ensure that we're keeping the
‫data across Compose restarts.
‫If we do a docker compose down now, after we have this data volume in there, it won't actually remove that
‫data volume, unless we do a -v on the end, which tells it, 'hey, I also want to delete the volumes.'
‫I think that's right.
‫Drupal data var lib postgres
‫SQL data.
‫All right.
‫Then I need to also put that down here.
‫Data.
‫All right.
‫I think we're ready.
‫Saving my files.
‫Let's see if we can do a docker compose up. OK, let's check our browser localhost 8080.
‫All right.
‫If this all worked, I can walk through this install like we did before
‫and postgres postgres
‫mypasswd
‫postgres. Save and continue. I'm going a little fast this time because I figure you've done it before.
‫I'm going to configure the site real quick.
‫OK.
‫We're on the site, and the instructions tell us to go to the appearance tab and notice we're on the
‫Bartik default.
‫We had this uninstalled theme down here that wouldn't have existed had we not installed it with
‫our image.
‫I can click install and set as default.
‫Then click back to site.
‫I have a totally new theme on my site using the bootstrap framework from Twitter which is a pretty
‫popular
‫templating system for CSS and websites.
‫So,
‫everything works as it should.
‫If I went back and actually stopped this, abort it, and then did a down, it's actually going to delete
‫the images.
‫But remember, it's not going to delete the data.
‫If I did a docker compose up again, what should happen is all those config files in the Drupal modules
‫and profiles, and sites, and themes, and then the data that's actually in the database, should all still
‫be there.
‫I should be able to hit refresh and it still works.
‫What's great about this way is that you can actually keep your images and your containers relatively
‫clean.
‫That way, when you're shifting between projects, you could technically get rid of that stuff and just
‫leave it alone...the volumes...the volumes alone...don't delete the data in them. Just leave the volumes
‫alone and don't delete their data.
‫Then when you come back to the project, you've already got all the sample data already in there and
‫you don't start from scratch.
‫All right. That's it.