what's going on guys? In this video we are going to build a docker container for our Golang application and before doing that we are going to quickly set up go modules that will allow us to manage the application dependencies efficiently and also will help us to download those libraries to build and run the application using docker containers. Remember to subscribe to the channel and remember to download the Golang Cheat Sheet, there is a link in the description below this video. Okay this is the Golang application that we've been working on, it's applying a clean architecture approach so we are independent of the database, we are independent of the HTTP router that we want to use in this case we're using Mux but we can also use Chi router or we can use Gin-gonic and in this case we are using SQLite as the database but we can use any other database such as Firebase. MySQL, Postgres or any other database engine. Ok, now we are going to set up Go modules in our application and then we are going to make a few changes mostly related to package names and after that we are going to create a Dockerfile to build the docker image. First I'm going to initialize the module for the application so I'm going to run "go mod init ..." and here the convention is to use the repo URL so I'm going to grab that from Gitlab and I'm going to remove "https://" okay I'm going to run this and this is going to create this go.mod file and now we need to use this package name and apply that name here in all the local folders that we are using to declare the packages that we need to import on each file so I'm going to do that (refactoring....) okay I already changed all the dependencies to include the module name for the application we can see that it's going to automatically declare all the external libraries that we are using here in the go.mod file and also it's going to create this go.sum file where includes all the URLs that is using to download the dependencies and it's going to associate a hash to each download so using this hash is going to ensure that future downloads of these modules will retrieve the same content and the same bits as the first download okay before creating the Dockerfile I'm going to make a few changes here so I'm going to remove this we are not going to use it anymore and I'm going to remove this port declaration from here and I'm going to use an environment variable (instead) so I can include that environment variable setup within the Dockerfile when I create the image so I'm going to remove this and I'm going to use the OS library to access the environment variable and I'm going to use the "Getenv" function and here I'm going to pass the name of the environment variable that in this case is going to be the port where the HTTP server is going to be listening in the application so I already exported that environment variable so we can see it here "echo $PORT" and I've already assigned the port 8000 for that environment variable so, let's run..., just to check that everything is still working, "go run *.go" and as we can see the application is running on port 8000 so let's quickly check that everything is working as we expect so we don't get any posts so I'm going to create one I'm able to create it and if we go here again and we execute a get request yeah we get the post that we've just created so everything is still working as we expect... I'm going to close this and now I'm going to create the Dockerfile okay I'm going to create a new file here.. it's gonna be Dockerfile, I'm going to close this okay I'm going to "Close others" okay... first we need to use a base Golang image so I need to use FROM and here we need to include a base image in this case we're going to use the latest Golang docker image that is going to include all we need to run our application it's going to include a Linux installation and it's going to include the latest Golang version so I need to... sorry... like this "golang:latest" ok the next thing is going to be LABEL and here I'm going to include the maintainer info in this case is going to be my information so this is gonna be... "maintainer..." and it's gonna be myself and here I'll include the email hello at pragmaticreviews.com okay the next thing is going to be the current working directory inside the container so this is gonna be WORKDIR and here is going to be a "/app" like that okay the next thing that we need to include is we need to copy these two files: the go.mod file where we have all the dependencies that are required to run the application and the go.sum file that includes all these hashes so we need to COPY the source is going to be go.mod and we need to you use another one... sorry and we need to use period to specify the destination folder that in this case is gonna be the WORKDIR that we specified here and here we need to COPY go.sum and we also need to use period to specify the current folder in the container okay so the next thing that we do is we need to RUN go mod download this is going to download all the dependencies that we define here in the go.mod file, the next thing that we need to do is we need to COPY all these files to the container so here we use copy all the files recursively to the destination that's gonna be the current directory within the container that is this one: "/app" ok the next thing that we are going to do is specify this environment variable the PORT environment variable so let's do that so we need to use ENV, like this and here is going to be PORT and the value is gonna be 8000 now what we need to do is we need to build the application so we need to include RUN go build and finally we need to specify the command that we want to run once the container is initialized so CMD and here we need to specify the command if we run here "go build" we're going to see that this "golang-mux-api" is an executable file so we can run it like this: "./golang-mux-api" and this is going to start the server so that's what we need to run once the container is initialized so I'm going to copy that here and that's pretty much all we need so I'm going to clear this and I'm going to run the command to build the image so first I'm going to run docker images to list all the existing images so we don't have any images, so I'm going to run docker build -t golang-api, that is going to be the name of the image and the directory that includes the docker file: "." so i'm going to run this and this is going to take a while and it's going to run each of these sentences now it's downloading all the dependencies that we're going to use in our application okay now it's going to copy all the source files it's going to set the port for the application and it's going to build the application. Ok, now our "golang-api" image is ready so if I run "docker images" I shall see the image listed there, here, and now I'm going to run the container using that image so "docker run -p ..." and here I need to specify the local port and the container port let's say that I want to use 8080 locally and the container port is 8000 the one that we specified here and now I need to specify the image name that is "golang-api" okay now the application is running and here I need to change the port here by 8080 and if I run this so this returns an empty array because we don't have any posts I need to change the port here as well and I'm going to create a new post and now if I run the GET operation yes I get the post that I already created okay now we know that our container is running I'm going to stop this and if I call this again yeah we don't get the response because the container is not running. That's pretty much all I have for today, thank you guys for watching. Remember to download the Golang "Cheat Sheet", there is a link in the description below the video, and I see you guys in the next one, take care, bye!