From the course: DevOps Foundations: Containers

Lightweight dev environments with Docker

From the course: DevOps Foundations: Containers

Lightweight dev environments with Docker

- [Instructor] For this lesson, we're going to walk through a hands-on example of how a container could be used for a very lightweight development environment. I'm using Docker desktop for this, which I've already installed. And we also need an example application to run. So I'm using an open source application called get Gitea, which I've already downloaded to a folder on my desktop here. The idea here is that this same process could be used for a developer looking to set up their own app in a container, but Gitea is pretty convenient because it's shipped as a single binary, which will make this a little bit simpler. I'm running Windows, but I downloaded the Linux version of Gitea because this is going to be running inside a Linux container. To define my container, I need to create a Docker file, and I'm just going to make a new text document to start. I'll just call it a Dockerfile.text and I'll double-click that to open up notepad. And I'll just increase the font size. Let me write a little bit first. So the first command I'm going to say is from, but then let me just zoom in. So I'll say from, and I want to tell Docker what base image we're going to use for our container. So I'm going to say alpine:latest. And Alpine is a Linux distribution that is a pretty common base image for containers, and it's really lightweight and small. It's only about five megabytes. And this is just telling it to get the latest version of that next. I want to copy in my Gitea file. So I'll say copy and I'm going to say ./ which is the local directory. And then I'll type in this long file name, for Gitea, gitea-1.14.4-linux-amd64. So that's my source file and then I want to give it a destination within the container and I'll just call it Gitea. There is one package dependency we'll need to run Gitea and that is Git. So I'll use the run command and these are all the commands that are going to be used by Docker when it builds this image. So one of the things that it'll do after copying the file is it'll run this command. I'll use the APK command. This is Alpine Linux's command for installing packages. APK add git. And there's one other thing I need in my file. And that is CMD/gitea. And that just tells Docker what command I want it to run by default when it runs this container. And that's it for our Docker file. So I'll save it and close notepad. And I just want to change my file extension here so that it's just a Docker file. And I'll say yes to this alert. So now I should be ready to build the Docker image and to do that, I'll just right click in my directory here. And I'll say open in Windows terminal. So here's my terminal window. And in order to build my container, I just need to say Docker build and then dot for my current directory. And I'll say -t to give it a name. I'm just going to name it Gitea. So now Docker pulls up that Docker file I created and it's running through all the commands, including downloading the base image for Alpine. That was pretty quick. So now that that's complete, we should be ready to run Gitea. So the command here is Docker run and then -d to tell it to run in detached mode that way it doesn't take over my terminal. And then -p. I'm going to tell it what port I want it to map. So Gitea will run on port 3000 by default, but unless I tell Docker that I want that available on my workstation, it'll just be within the container. So this is telling it to let me get app port 3000 on my own laptop. And then I'll tell it the name of the container I want to run, which is Gitea. And this long string of letters, numbers is the unique code for that container that's running. So I should be able to see this in a web browser now. Let's see what we have. So I'll just need to go to local host:3000. And here's my Gitea server. Now I'm going to just set this up. One of the reasons I wanted to pick Gitea is it has this nice little configuration page. And you can see, you can set it up with MySQL, which we'll do in the next lesson, but for now I'm going to use SQLite, which is just a self-contained file system based database. And I'll scroll down to the bottom. These defaults should be okay for now. And I'm just going to set up this, which is my administrator account. And I'll say, install Gitea. Now this'll take a second. And here's my Gitea server. This is actually a pretty nice little web app. This is just as intended as an example. The course isn't about this app, but it's a nice little clone of GitHub. And it's a pretty easy little self hosted application to play around with with quite a few features. This app is a pretty simple example, and there are very few web apps that have such a minimal environment and would be so easy to set up. But I hope this gives you a taste for what's possible with containers. Here we've got a Linux-based web app with a bundled dependency package running on a Windows workstation. If I shared this Docker image with a colleague using a Mac, it would work exactly the same for them.

Contents