Docker Useful Commands

Enable Hyper-V

Ensure virtualisation is enabled on your machine (Powershell):

> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

You will need to reboot afterwards. Open your console and run:

> docker --help

You should see a list of docker commands.

Create image

> docker create -t -i {imagename}

Create container

> docker {containername} -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.4.3

Start container

> docker start {containername}

Stop container

> docker stop {containername}

Remove container

> docker rm {containername}

Remove image

> docker rmi {imagename}

Docker Build

This allows the container to be pulled and used in the yaml that deploys to Kubernetes:

> docker build -t {AcrInstanceName}.azurecr.io/training:sample .

Push images to Container Registy

> docker push {AcrInstanceName}.azurecr.io/training:sample

Example - running golang as a container

You can use the Docker command line to create a container in a few seconds. Let’s grab a Linux distro with GoLang SDK:

> docker pull golang

This will grab the latest golang image i.e. golang:latest. You can check that by looking at all your current images:

> docker image ls

|REPOSITORY| TAG |IMAGE ID |CREATED |SIZE|
|--|--|--|--|--|--|
|golang| latest |d817ad5b9beb |10 days ago |774MB|

In its simplest form an image is a template for a container and a container is an instance of the image. You can have many containers running from the same image.

You can start a container instance and access it interactively:

> docker run -it golang

This should take you directly to the go directory, logged in as root. You can check the OS that is being used:

> docker uname -a

Linux 51c25d4da212 4.9.93-linuxkit-aufs #1 SMP Wed Jun 6 16:55:56 UTC 2018 x86_64 GNU/Linux

You can see it is running a Linuxkit image on kernel v4.9.93. Linuxkit is designed for creating lightweight custom containers: https://github.com/linuxkit/linuxkit

Close out of the container by typing exit. And then verify that you were running in a container:

> docker container ls --all <or> docker ps -a

The --all (or -a) param will display all containers. Without it only running containers will be displayed.

You can remove the golang container by getting its Container ID or auto generated Name:

> docker rm elegant_vaughan

You can remove the image in a similar way:

> docker rmi golang
0 visits in last 30 days

Comments