WHT

Learn Docker In 12 Minutes | Learn Docker In 12 Minutes 🐳

Jake Wright

Subscribe Here

Likes

44,129

Views

1,891,943

Learn Docker In 12 Minutes 🐳

Transcript:

Docker is a tool for running applications in an isolated environment. It gives you advantages similar to running your application inside a virtual machine. Some of those advantages are your app always runs in exactly the same environment, so you don’t get inconsistencies in how it behaves If it works on your computer, it works on every computer. It works on the live server. It always acts the same. If you’re working on multiple projects, it lets you sandbox each one and keep them separate good for security and eliminate a potential conflict between different projects and, Lastly, it makes it easier to get going with somebody else’s projects. You don’t have to install all of the tools and dependencies that the project needs. You just spin up the virtual machine. Put your call inside and it works. Doctor gives you these advantages, but without the overhead and hassle of running and managing a virtual machine. Instead, we have containers the code and the environment are all wrapped up inside a container, but a container is not a full virtual machine. When you’re going to virtual machine, each machine gets its own full operating system, including the kernel. The kernel is like the core of the operating system, the bit that controls the low-level stuff, and this is quite resource heavy on the host machine, the computer running the virtual machine’s containers, however, they all use the host machines kernel. A core bit of the operating system is shared, but everything on top of that is still separated. Everything that makes a Linux distribution unique because all Linux distributions are boon to Debian, etc are all built on the same kernel and darker uses special features of the UNIX file system to create these isolated environments so containers are compromised. The separation and Sandbox is not quite as extreme, but it’s enough, and as a result, a container can start up in seconds as opposed to minutes, they use fewer resources to take in a blessed disk space and using less memory, so a container is a running instance of an image. An image is a template for creating the environment. You wanted to snapshot of the system at a particular time, so it’s got the operating system. The software, the application code all bundled up in a file images are defined using a docker file. A doc file is just a text file with a list of steps to perform to create that image, for example, you to configure the operating system install the software. You need copy the project files into the right places, etc. So you write a darker file. Then you build that, and you get an image which you can then run to get containers, so lets. Try out this whole process. First you’re going to want to install docker for Mac or for windows Links are in the description. This is just some software to allow Docker containers to run on your computer and unless you’ve got a specific reason to use it, Ignore docker toolbox. That’s the older way to run docker on a Mac or PC. I’ve created a new folder just on my desktop for this demonstration and I’m going to write a super simple Hello, World application in PHP. It’s literally just going to echo Hello world, and I’m going to save that in a folder called SRC for Source as Index Dot Php. Right now you can’t execute that file. You need a web server. Our goal is to use docker to create one, so let’s make a new file and we’re going to call this docker file. We’re going to save it next to the source folder, not inside Docker file Capital, D one word and in here we’re going to use cold to configure our environment, so for this we want an operating system with PHP and Apache installed Apache is the Web server software. The cool thing, though, is we don’t have to start from scratch. We start in our docker file with the name of an existing image, an image that has already been built and then we build on top of that. Conveniently, you can find lots of existing images on at the docker hub. So if you go to hub Docker com sign up, the search doesn’t seem to work. If you logged out, you can search for images so we can search for a PHP image. Now the hub includes images from the whole community, so it’s up to you to decide if the image is suitable and well-maintained the best ones to look out for are the official ones. Luckily for us, an official. Php image already exists at the top youll. Find all the variations of the image. These are called tax, so we just want to like the latest version of PHP, and we want to patch it as well. So this line right here. This has a few versions of PHP with Apache going left to right. They get less specific, so this will give you specifically 7.0 point 10 all the way to the end where this will always just give you the latest version of PHP, that ones usually a bad idea, though, because that means PHP could just unexpectedly be upgraded and a might break your old code, but one of these are the ones is fine for us now. If you scroll down, you even get instructions, telling you how to use the image if you find the Apache section, it tells you what to put in the dockerfile. So we first want to define the base image using the from keyword and we want then name of the image PHP, then a colon and the name of the tag, so we’ll use as suggested 7.0 – Apache, and then we want to copy our files inside the image using the copy keyword, so we want to copy the contents of source into slash Var slash www slash HTML there, just telling us here that this is where Apache will look on its own file system and to find the file, so we should put our files there and you can see now why? I called that folder source, just so it matches these instructions. We want one more thing in our doctor file. We want to use the expose keyword to expose Port 80 This just means when you run the image and you get a container that container will listen on Port 80 by default, it will just ignore all incoming requests if you’re wondering what operating system this? Php image is based on you can usually find the Daka file that it’s defined by in this case it’s linked next to the tag names, and we see it’s based on Debian. Similarly, that Debian image will have a doorknocker file and they’ll stack on top of each other, like I said earlier And this layering of images is a huge advantage of using docker, the PHP stock. You file is a little bit more complicated than ours, but let’s just focus on ours for now. So when we build our docket file, Docker is going to download PHP from the docker hub. It’s going to copy our files from source to this location inside of the image, It’s going to tell running containers to listen on Port 80 and then it’s going to output a new image, our new customized version, which will be able to run so to build it. I’m going to go to a terminal first. I’m going to move to the folder that it’s in so we can see. We’ve got docker file right there, and I’m going to type docker A build dash T to give it a name. I’m just going to call it. Hello, world. And then at the end, you want to tell it the location of the docker file and since it’s in the current directory, we just want to put a dot to say that woops helps if I save the docket file first. The first time you do this, It’ll have to download all of the layers that make up that. Php image shouldn’t take too long wanted to got the image. It’s going to copy our files inside at the end, its outputs our new image and it’s going to be called. Hello, world. So we can run this by typing docker. Run, hello world. There’s one other thing we need in the middle of this. We need to use the dash. P tag to forward a port port 80 from the host to port 80 in the container. So that means when a request gets the host. The host is your computer when a request gets there, Doctor is going to forward that to the container and when it gets to the container that X pause line that we’ve got in the docker file that will let the container accept the request and allow Apache to handle it so we can run that. We’ll get some output from the container from PHP, and then we can go to localhost and we’ll see hello world, so we’ve done it. We’ve got our application running inside a docker container. Now if you go back to index Dot Php, and you change this when you refresh localhost, it won’t change. The the docker container won’t reflect the new version of the file and this is because when we built the image, it made a copy of that file to see the change you’d need to rebuild the image and spin up a new container from the updated image during development. This is obviously a massive pain, and this is where volumes come in. So there are two types of volumes want to persist and share data between containers. We only have one container. I’m not going to talk about this today, but the second type. Lets you share folders between the host and the container. You can mount a local directory on your computer. As a volume inside the container, then the container when it’s running, we’ll be able to see the files that we’re working on hit control-c to stop this container to mount a volume we’re going to add another option to the docker run command. We’re going to add dash. V and we want to tell it to mount the the folder users slash Jake Slash desktop. It needs to be the full path, not a relative one slash docker slash SRC. So we want that folder that local folder to be mounted to put a caller inside the container and slash var slash www HTML, so the image, it copies this folder to this location inside the container, but during development, we don’t just want to copy. We want to see that folder. We want a live view of that folder so we can mount it at that directory. So this time when you run it, you’ll see changes that we make are reflected straight away as soon as we refresh. The docker container can’t see that change in the file because it’s looking at the file itself, so this is really useful during development, But before you deploy this and try to run the image somewhere else, you will need to rebuild the image to get an updated copy of the files put inside volumes. Just give a running container the ability to see files on the host machine’s filesystem they do not change the image. So when you’re done, you can press ctrl C to stop the container again. So one last thing I want to mention you can see. We can easily stop a container manually by pressing Ctrl C. But containers will stop by themselves when the main process exits in this case that would only be if Php died for some unexpected reason, But you can equally make containers with short running tasks. You might have a container which runs tests or a container which runs composer install. The process running in these containers will end when the task is complete, and when that main process ends, the container will stop. So for this reason, you should endeavor to have one process per container because the life of that container is tied directly to a single process. So you don’t want 5 other things going on in the background that will all be brought down when without warning when the main process turn it and the ten, it just stops, but since containers are really lightweight, you can run loads and loads of containers on your computer all at the same time, and it’s no problem at all, so we found a suitable image as it uses a base image on the docker hub, we wrote a dock or file to augment that image, and then we built that to output our new customized image, which we could then run to get a container which would run our application. We mounted a volume using the dash. V tag and we ended up with a docker container running granters. It’s a very simple application, but it is that easy. Three line docker file gets this up and running in a future video. We’ll look at more complex situations and we’ll look at orchestration, options and deployment options. So you can get your container to run a website on the Internet. Please let me know how you found this video. Feel free to ask any questions. I’ll try to answer as many as possible either in the comments or in a future video. Thanks for watching.

Wide Resnet | Wide Resnet Explained!

Transcript: [MUSIC] This video will explain the wide residual networks otherwise known as wide ResNet and then frequently abbreviated in papers as wrn - the number of layers - the widening factor, so the headline from this paper is that a simple 16 layer wide. Resnet...

read more