Skip to main content

Docker on Windows - Part 3 Creating A Container with Docker Compose

Welcome back and thank you for checking out my third and final blog post in the series of running Docker on Windows. In the first blog post, we set up Docker on Windows. On the second, we spun up an Nginx container. Today, we're going to spin up an Nginx container, but do it the automated way with Docker Compose! Docker Compose is a manifest file of your container and it's settings. You can have one container in your Docker Compose file or multiple. Let's get started.

First, let's confirm Docker Compose is installed and running on your system. Open up PowerShell and run:
docker-compose

If you see several switches and commands, you are good to go! If not, please confirm you installed Docker with the instructions in the first blog post of this series.


Next, we're going to open up VSCode. If you do not have VSCode installed, please do so by following this link: https://code.visualstudio.com/

Once VSCode is open, we want to ensure we have a few extensions. Those two extension are YAML by RedHat and Docker.



Next, let's go ahead and open up a new file. We can save this file on our desktop. 

Please Note: For production code, you'll want to get in the habit of storing this in a Git repo. That way you can write whatever Compose files you want, then git push the code up to your repo where it is safely stored. For testing purposes, we'll go ahead and put it right on our desktops.


Now, let's start writing our Compose file! 

The first thing we'll specify is our API version for Docker Compose. This will be version 3.


Next, we're going to start with our service block. The service block in our case, is Nginx.



Please note the two spaces under "services" for "nginx". This is a standard YAML syntax. Please ensure to follow it so you don't receive any errors.

Let's call our image now. Remember in part 2 of the docker series when we pulled down an image? This is the same thing essentially.



Now that we have our image, let's give our container a name!


Next we're going to do a little Docker trick. One of the features of a container is to start the container > run the application > stop the container. In our case, we don't want to do that. We're going to run a command to tail anything. This essentially keeps the container running because it's a never-ending command.


Let's specify our volumes. Volumes can be used for a few purposes. Specifying persistent storage and mounting a specific file in the container. For our purposes, we want to mount a specific nginx.conf config file in our container. We will do it like so:


The first part is where my Nginx config that I want to import into my container is living. In my case, it's on my desktop. Then I have a colon separating where the config is, and where it's going. In our case it's going to /etc/nginx/nginx.conf. Look at it as the "source" is on the left and the "destination" is on the right. Putting in an Nginx config file is purely your choice. I did it for the purposes of showing a part of what volumes are.

Finally, we're going to go ahead and specify our ports.


It is very important to have that colon followed by the port again. If you don't, Dockers networking will forward your app to a different port.

Next, let's go ahead and save that to our desktop. We want to name it "docker-compose.yml" as that is the naming convention for a Docker Compose file.

Let's get back into PowerShell and kick off our Docker compose config. You'll want to run:
docker-compose up -d


What this will do is spin up the Docker Compose config file that's in your location of where you are in your shell, and the -d is to detach from the container. If you don't do that, your shell will be stuck in the "running" state of the container and if you CTRL + C, it'll kill the container.


Note that my current location in my shell is my desktop, which is where my Docker Compose file is living.

Now, let's kick it off!


My screenshot shows "creating". This was because I was testing this prior :).

Because Docker needs access to your C: drive, you may see a pop-up on the bottom right of your screen to allow access to Docker. You'll then be prompted for your password. This is, in short, a UAC prompt, but for Docker. If you are not comfortable doing that, please feel free to run this in a VM instead.



Now, let's run docker container ls to see our container running.


Finally, let's do a docker exec -ti yourcontainerid /bin/bash and cat /etc/nginx/nginx.conf

If you imported an nginx.conf file, you'll see your entries. In my case, I just created a bogus nginx.conf config for testing purposes.


There you have it! You have now successfully spun up a container in an automated fashion with Docker Compose.

I truly hope you all have enjoyed the 3 part Docker in Windows series. It was a pleasure writing the content and thank you everyone for reading.

Comments

Popular posts from this blog

So, you want to be a Cloud Engineer?

In 2019 one of the biggest pieces of tech is the cloud. Whether it be public cloud or private cloud, cloud technologies are here to stay (for now). I predict that Cloud Engineering will be a very big part of IT (and development) for another 5-10 years. Today I want to share with you my journey in becoming a Cloud Engineer and some helpful tips. A career timeline to be a Cloud Engineer can go like so;

Desktop Support > Junior Sysadmin > Sysadmin > Sysadmin/Technical Lead > Engineer >  Cloud Engineer.

Although our career paths may not align, I believe that this progression is very import. Let me tell you why.



Helpdesk/Desktop Support Helpdesk and desktop support get your feet wet. It allows you to understand technology and how it's used in the workplace from a business perspective. It shows you what technologies may be best in the current environment your in and how to support those technologies. It also teaches you soft skills and how to support people from a technic…

Monitoring your containers in an AKS cluster with Prometheus

Monitoring and alerting is arguably one of the most important thing in Cloud Engineering and DevOps. It's the difference between your clients stack being up and a client being down. Most of us have SLA's to abide by (for good reason). Today we're going to learn how to spin up Prometheus in an AKS cluster to monitor our applications.

Pre-reqs;
1. Intermediate knowledge of Kubernetes
2. An AKS cluster spun up in Azure

Recently AKS supports Prometheus via Helm, so we'll use that for an automated solution to spin this up. This installs kube-prometheus, which is a containerized version of the application. With raw Prometheus, there are a few things that are needed for the operator;

1. Prometheus: Defines a desired deployment.
2. ServiceMonitor: Specifies how groups of services should be monitored
3. Alertmanager: Defines the operator to ensure services and deployments are running by matching the resource

With kube-prometheus, it is all packaged for you. This means configuri…

Spinning up a Kubernetes cluster with Kubeadm

In today's world, we have several public cloud technologies that will ultimately help us with spinning up these infrastructures. This however comes with a price. Because a public cloud provider (like AWS or Azure) handles the API/master server and networking, you'll get something up quick, but miss some key lessons of spinning up a Kubernetes cluster. Today, I'll help you with that.

There are some pre-reqs for this blog:
1. At least 3 VM's. In my case, I'm using my ESXi 6.7 server at home.
2. Basic knowledge/understanding of what Kubernetes is utilized for.
3. Windows, Mac, or Linux desktop. For this blog, I am using Windows 10.

The first thing you want to do is spin up three virtual machines running Ubuntu18.04. You can use a RHEL based system, but the commands I show and run (including the repos I'm using) will be different.

I have already set up my 3 virtual machines. I gave them static IP addresses as I have found API/configuration issues if the VM shuts do…