First hands on with Docker

For me, learning about containers (and Docker in particular) is just part of my journey to keep up to date on the tools of modern software development. I don’t anticipate becoming a container expert or managing large Docker swarms (although you never know!), but having a decent understanding of the tools and technologies around containers fits into my process of using the best tools available for a given problem.

Why learn Docker?

For me, learning about containers (and Docker in particular) is just part of my journey to keep up to date on the tools of modern software development. I don’t anticipate becoming a container expert or managing large Docker swarms (although you never know!), but having a decent understanding of the tools and technologies around containers fits into my process of using the best tools available for a given problem. I am fascinated to learn new ways to accomplish a task, not to mention that using containers for software development seems to be an idea that is sticking around. With that in mind, let the learning begin!

What exactly is Docker?

I won’t even pretend to give a better executive summary of containers and Docker than Docker themselves do, so I will spare you the attempt.

For a good overall summary of what Docker (and containers and images) is, I headed to the official Docker documentation, and was quickly up to speed on the overall benefits and high level idea behind containers.

Install Docker

While I primarily develop on Windows, for this project I wanted to utilize Linux as forced way to brush up on other skills that often do not get enough attention due to time constraints. I happened to have a Linux instance available from a previous project, so I fired it back up and connected to it via Windows Subsystem For Linux and SSH.

I installed the Docker CE (Community Edition)

My Linux install was Ubuntu based (Amazon Linux AMI), so make sure to use the proper instructions for your version of Linux.

Instructions I followed for Docker

Uninstall old versions of Docker

Don’t skip this step! I had a previous version of Docker installed (without knowing what I was doing), so I wanted make sure that was cleaned up first. If nothing was previously installed, nothing bad will happen.

Install and Confirm

Once I cleaned up my old install of Docker, I was able to successfully reinstall the current version of Docker CE, add my user to the docker group, and confirm the running status of Docker. Success!!

Create a Docker image

I ended up following the AWS introduction guide to Docker and created a ‘Hello World’ image that served a static web page from an instance of Apache. The tutorial was pretty straightforward, I only needed to tweak my AWS security group for the EC2 instance to allow for inbound connections on port 80 from my machine.

Dockerfile

FROM ubuntu:16.04

# Install dependencies
RUN apt-get update
RUN apt-get -y install apache2

# Install apache and write hello world message
RUN echo 'Hello World!' > /var/www/html/index.html

# Configure apache
RUN echo '. /etc/apache2/envvars' > /root/run_apache.sh
RUN echo 'mkdir -p /var/run/apache2' >> /root/run_apache.sh
RUN echo 'mkdir -p /var/lock/apache2' >> /root/run_apache.sh
RUN echo '/usr/sbin/apache2 -D FOREGROUND' >> /root/run_apache.sh
RUN chmod 755 /root/run_apache.sh

EXPOSE 80

CMD /root/run_apache.sh

Build docker image

docker build -t hello-world .

Verify image

docker images --filter reference=hello-world

Run image

docker run -t -i -p 80:80 hello-world

I added the -t -i flags to allow Ctrl+C to be used to interrupt docker run. See this GitHub issue for a more complete discussion.

test!

Summary

I obviously still have lots to learn, but this first look at Docker was relatively painless and has already given me a whole set of ideas to try out and incorporate into my development processes.


Featured image by Tim Easley @ unsplash.com

Opening Windows Command Prompt and PowerShell to current Explorer location

I recently came across an article (wish I still had the link) that mentioned how to quickly open a command prompt with the same working directory as the current folder in Windows Explorer.

All these years using Windows and it is still so easy to learn something new!

I recently came across an article (wish I still had the link) that mentioned how to quickly open a command prompt with the same working directory as the current folder in Windows Explorer.

For so long I have used the painful process of copying the current location from the Explorer address bar, opening a command prompt and typing in:

cd /d {folder path}

Solution

The solution is so obvious that it is a little painful to just be learning it now. 🙂

From the explorer window, just type cmd into the address bar and hit enter.

Bingo!

Powershell

Also works with PowerShell!

Nice!

Going in reverse

And of course, to go from a command window to Explorer to browse the current working directory of the command window, just type in explorer . into the command window and hit enter.

Browse away!

While I wish I had thought to try this years ago, I’m at least glad I know it now. It’s never to late to learn a new trick.

Troubleshooting and turning on SQL Server Authentication mode

Anyone who has ever connected to a remote system before has invariably encountered authentication or connection issues. Unfortunatly, due to the security implications of connecting to remote systems, the error message returned is not always helpful.

Scenario

Anyone who has ever connected to a remote system before has invariably encountered authentication or connection issues. Unfortunatly, due to the security implications of connecting to remote systems, the error message returned is not always helpful.

For instance, I came across the message below when trying to connect to a remote SQL Server instance using SQL Server Management Studio (SSMS) and SQL Authentication.

Cannot connect to '{server}'.

Additional information:

Login failed for user '{username}' (Microsoft SQL Server, Error: 18456)

Not initially very helpful.

Troubleshooting

To Google we go!

Hang on. There is a better way to go about this! We have an error code, so a good starting point for detailed information is the SQL Server errors page.

The error page for MS SQL Server error 18456 gives some potential causes, but narrowing down the root cause required more detailed error information.

Server Logs

The SQL Server Log will give you more detailed information related to the error, specifically a more detailed message and a state code to accompany the error code. If you do not have access to the server you will need to request the information from your server administrator. However, if you do have access, there are 2 different ways to view the logs.

1.) On the server itself, the error logs will be located in a director similar to this path:

%Program-Files%\Microsoft SQL Server\MSSQL.1MSSQL\LOG\ERRORLOG

2.) In SSMS you can access the same logs using the Object Explorer to navigate to:

SSMS -> server node -> Management -> SQL Server Logs

Detailed Error

In this case, I quickly found the details of the error:

SQL Server error 18456, severity 14, state 58

Login failed for user {username}. Reason: An attempt to login using SQL authentication failed. Server is configured for Integrated authentication only. [CLIENT:{ip address} ] 2019-03-01 14:25:36.60 Logon Error: 18456, Severity: 14, State: 58.

OK. Here now we have an error state code: 58. Unfortunately the error documentation from Microsoft does not specifically reference a reason for this state. However, the detailed error message tells us that the authentication failed because the server is configured for Integrated (Windows) authentication only and we are trying to log in with SQL Server credentials.

Authentication Modes

We can confirm that the server is indeed NOT set up for mixed authentication in two ways:
1.) By querying the SQL Server property related to Integrated Security:

<span class="token keyword">SELECT</span> SERVERPROPERTY<span class="token punctuation">(</span><span class="token string">'IsIntegratedSecurityOnly'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  • If the return value is 1 then the server is configured for Windows Authentication only.
  • If the return value is 0 then the server is configured for Windows and SQL Server Authentication (mixed authentication). See documentation related to server properties for more details.

2.) In SSMS by going right clicking on the server node -> Properties -> Security.

If you are able to and need to change server authentication modes, refer to the authentication mode documentation for details and security issues pertaining to the steps.

Once the authentication mode has been changed, the authentication error should go away and a connection to the server can be established.

Summary

While troubleshooting error codes from any server or software can be challenging, taking the time to track down the proper documentation and detailed error logs can be well worth the time spent. The first few times may be quite time consuming to figure out, but writing down clean documentation and bookmarking resources will go a long way towards helping debug future errors.

This is a MUST BOOKMARK reference for MS SQL Server error logs:
https://docs.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors


Featured image by Robert Anasch @ unsplash.com