(basic / useful) Docker commands

Disclaimer: This is a list of commands/options I found most useful in my day-to-day activities, there are many commands/options available, you may find other commands/options more useful or use them in another way.

Basic ( runtime check )

docker -v
docker info

Basic ( listing )

docker ps (containers running)
docker ps -a (last run containers)
docker images (existing images)

Basic (creating / deleting )

docker pull [image name]
docker run -it [image name] [command] (runs a command in a container based on an image) 
docker stop [container name] (stops the container)
docker start -ai [container name] (starts the container)
docker stop $(docker ps -a -q) (stops all containers using ID)
docker exec -it [container name] [command]
docker container top [container name]
docker rm [container name] (removes a container)
docker container prune (removes all stopped containers)
docker rmi [image name] (removes the image)
docker rmi $(docker images -q) (removes all images using ID)
docker image prune (removes unused images)

What are your most useful commands?

Advertisements
Posted in docker | Leave a comment

Do you know you can override the == operator ?

Yes you can!

In order to override equality in Value Types we should :

  • implement IEquatable
  • override object.Equals()
  • implement ==
  • implement !=
  • implement object.GetHashCode()
public struct FoodStruct : IEquatable<FoodStruct>
{
    private readonly string _name;

    private readonly FoodGroup _group;

    public FoodStruct(string name, FoodGroup group)
    {
        _name = name;
        _group = group;
    }

    public string Name
    {
        get
        {
            return _name;
        }
    }

    public FoodGroup Group
    {
        get
        {
            return _group;
        }
    }

    public override string ToString()
    {
        return _name;
    }

    public bool Equals(FoodStruct other)
    {
        return _name == other._name && _group == other._group;
    }

    public override bool Equals(object obj)
    {
        if (obj is FoodStruct)
        {
            return Equals((FoodStruct)obj);
        }

        return false;
    }

    public static bool operator ==(FoodStruct left, FoodStruct right)
    {
        return left.Equals(right);
    }

    public static bool operator !=(FoodStruct left, FoodStruct right)
    {
        return !left.Equals(right);
    }

    public override int GetHashCode()
    {
        return _name.GetHashCode() ^ _group.GetHashCode();
    }
}

Check Simon Robinson course on Pluralight about C# Equality and Comparisons

Posted in c# | Leave a comment

Back to the basics…

While watching this course from K. Scott Allen I’ve re-learned some things about Object Oriented Programming, namely this ..

If you have a class…

public class GradeBook
{
    public List<int> ListOfNumbers { get; set; }

    public int ReturnLowest()
    {
        int lowest = int.MaxValue;

        foreach (int number in ListOfNumbers)
        {
            lowest = Math.Min(lowest, number);
        }

        return lowest;
    }
}

and a derived class…

public class AugmentedGradeBook : GradeBook
{
    public int ReturnLowest()
    {
        int lowest = int.MaxValue;
        foreach (var number in ListOfNumbers)
        {
            lowest = Math.Min(lowest, number);
        }

        ListOfNumbers.Remove(lowest);

        return base.ReturnLowest();
    }
}

The c# compiler will choose the method to run based on the type of the variable.

[Theory]
[InlineData(new int[] { 1, 2, 3, 4, 5 })]
[InlineData(new int[] { 5, 4, 3, 2, 1 })]
[InlineData(new int[] { 5, 4, 1, 3, 2 })]
public void ReturnsLowestBaseClass(int[] listInts)
{
    GradeBook gradeBook = new AugmentedGradeBook();
    gradeBook.ListOfNumbers = listInts.ToList();

    var lowest = gradeBook.ReturnLowest();

    Assert.Equal(1, lowest);
}

Since we have a variable of type GradeBook gradeBook it will execute the method GradeBook.ReturnLowest();
On the other hand, if we have a variable of type AugmentedGradeBook gradeBook

[Theory]
[InlineData(new int[] { 1, 2, 3, 4, 5 })]
[InlineData(new int[] { 5, 4, 3, 2, 1 })]
[InlineData(new int[] { 5, 4, 1, 3, 2 })]
public void ReturnsLowestOwnClass(int[] listInts)
{
    AugmentedGradeBook gradeBook = new AugmentedGradeBook();
    gradeBook.ListOfNumbers = listInts.ToList();

    var lowest = gradeBook.ReturnLowest();

    Assert.Equal(2, lowest);
}

it will execute AugmentedGradeBook.ReturnLowest();

To achieve polymorphism we can change the class GradeBook to use a virtual method and then override the behavior in another class.

public class GradeBook
{
    public List<int> ListOfNumbers { get; set; }

    public virtual int ReturnLowest()
    {
        int lowest = int.MaxValue;

        foreach (int number in ListOfNumbers)
        {
            lowest = Math.Min(lowest, number);
        }

        return lowest;
    }
}

and the new derived class

public class AugmentedVirtualGradeBook : GradeBook
{
    public override int ReturnLowest()
    {
        int lowest = int.MaxValue;
        foreach (var number in ListOfNumbers)
        {
           lowest = Math.Min(lowest, number);
        }

        ListOfNumbers.Remove(lowest);

        return base.ReturnLowest();
    }
}

this way we can have a variable of type GradeBook gradeBook and the executed method will be AugmentedVirtualGradeBook.ReturnLowest

[Theory]
[InlineData(new int[] { 1, 2, 3, 4, 5 })]
[InlineData(new int[] { 5, 4, 3, 2, 1 })]
[InlineData(new int[] { 5, 4, 1, 3, 2 })]
public void ReturnsLowestVirtualAugmentedClass(int[] listInts)
{
    GradeBook gradeBook = new AugmentedVirtualGradeBook();
    gradeBook.ListOfNumbers = listInts.ToList();

    var lowest = gradeBook.ReturnLowest();

    Assert.Equal(2, lowest);
}

Hope it helps…
Cheers!

Posted in c#, Object Oriented Programming | Leave a comment

SSMS Templates : export and import

This week i’ve installed the SSMS  2014 and wanted to get my templates from SSMS 2012. Since there is no import / export feature i’ve found out this post from Grumpy DBA

In my case it was just copying from :

AppData\Roaming\Microsoft\SQL Server Management Studio\11.0\Templates\Sql

TO

AppData\Roaming\Microsoft\SQL Server Management Studio\12.0\Templates\Sql

Thanks Grumpy DBA

Grumpy DBA

Posted in SQL Server Management Studio | Leave a comment

MVC Layouts

I have found this very straightforward post about MVC Layouts…

http://www.dotnet-tricks.com/Tutorial/mvc/3WDE140613-Different-ways-of-rendering-layouts-in-Asp.Net-MVC.html

Simple but effective..

Posted in MVC | Tagged | Leave a comment

VS publish umbraco_client folder

While working on a solution that had umbraco installed from nuget, i kept noticing that in the visual studio output window while publishing the project to the file system the umbraco_client folder was being copied to the publishing folder. I believed something was wrong since visual studio only publishes files that are included in the solution and i usually don’t include it…

I was wrong … since version 2.5 of nuget packages, a conventional folder called “build” can be included in nuget packages. Now since version 6.1.3, the UmbracoCms nuget package changes your .csproj with

<Import Project="..\packages\UmbracoCms.6.1.3\build\net45\UmbracoCms.targets" Condition="Exists('..\packages\UmbracoCms.6.1.3\build\net45\UmbracoCms.targets')" />

And there it is, the conventional folder “build” with corresponding .props and .targets files making visual studio publishing those files..

UPDATE: The always helpful Morten Christensen aka @sitereactor gave me this feedback

“there is no conclusion to that post… Did you hate it or love it? Pleasantly surprised or annoyed?”

I do a lot of FileSystem publishing (with the option to delete all files before) in Visual Studio and with this in place the publishing does take a little longer…but it gives me a certain confidence that all files are the the newest! And it beats having to include / exclude those folders into the solution when publishing files after an upgrade!

Posted in umbraco, Visual Studio | Tagged | Leave a comment

This is how to reinstall a nuget package through the package manager console

PM> Update-Package [PackageId] -Reinstall

Gist Here

Link | Posted on by | Tagged , | Leave a comment