Wednesday, January 4, 2017

Learning Docker on windows and troubleshooting the errors - part 1

1) Download and install the docker tookbox from
https://www.docker.com/products/docker-toolbox

This installs multiple products, docker engine, docker swarm, oracle virtual box, kitematics, etc.


2) Launch the Docker quick start terminal as administrator

Usually, Note: If the CPU virtualization is not enabled in the BIOS, you get the below error (). Else, you will see no errors.

Creating CA: C:\Users\<<mylogonname>>\.docker\machine\certs\ca.pem
Creating client certificate: C:\Users\<<mylogonname>>\.docker\machine\certs\cert.pem
Running pre-create checks...
Error with pre-create check: "This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory"
Looks like something went wrong in step ´Checking if machine default exists´... Press any key to continue...

Follow this article to resolve the above error
https://github.com/docker/machine/issues/2256


--------------------
3) docker-machine

This will show you a help guide with the list of commands as shown below

$ docker-machine
Usage: docker-machine.exe [OPTIONS] COMMAND [arg...]

Create and manage machines running Docker.

Version: 0.8.2, build e18a919

Author:
  Docker Machine Contributors - <https://github.com/docker/machine>

Options:
  --debug, -D                                                   Enable debug mode
  --storage-path, -s "C:\Users\<<username>>\.docker\machine"    Configures storage path [$MACHINE_STORAGE_PATH]
  --tls-ca-cert                                                 CA to verify remotes against [$MACHINE_TLS_CA_CERT]
  --tls-ca-key                                                  Private key to generate certificates [$MACHINE_TLS_CA_KEY]
  --tls-client-cert                                             Client cert to use for TLS [$MACHINE_TLS_CLIENT_CERT]
  --tls-client-key                                              Private key used in client TLS auth [$MACHINE_TLS_CLIENT_KEY]
  --github-api-token                                            Token to use for requests to the Github API [$MACHINE_GITHUB_API_TOKEN]
  --native-ssh                                                  Use the native (Go-based) SSH implementation. [$MACHINE_NATIVE_SSH]
  --bugsnag-api-token                                           BugSnag API token for crash reporting [$MACHINE_BUGSNAG_API_TOKEN]
  --help, -h                                                    show help
  --version, -v                                                 print the version

Commands:
  active                Print which machine is active
  config                Print the connection config for machine
  create                Create a machine
  env                   Display the commands to set up the environment for the Docker client
  inspect               Inspect information about a machine
  ip                    Get the IP address of a machine
  kill                  Kill a machine
  ls                    List machines
  provision             Re-provision existing machines
  regenerate-certs      Regenerate TLS Certificates for a machine
  restart               Restart a machine
  rm                    Remove a machine
  ssh                   Log into or run a command on a machine with SSH.
  scp                   Copy files between machines
  start                 Start a machine
  status                Get the status of a machine
  stop                  Stop a machine
  upgrade               Upgrade a machine to the latest version of Docker
  url                   Get the URL of a machine
  version               Show the Docker Machine version or a machine docker version
  help                  Shows a list of commands or help for one command

Run 'docker-machine.exe COMMAND --help' for more information on a command.

----------------------

3)  Now, pulling a helloworld image from docker hub (https://hub.docker.com/)
Note: You can use the Kitematics (to perform the same using a GUI instead of command line)

docker pull kitematic/hello-world-nginx

You may run into below error.
---------------------------------
$ docker pull kitematic/hello-world-nginx
Using default tag: latest
Pulling repository docker.io/kitematic/hello-world-nginx
Network timed out while trying to connect to https://index.docker.io/v1/repositories/kitematic/hello-world-nginx/images. You may want to check your internet connection or if you are behind a proxy.

------------------------------

Don't worry, to resolve this, sometimes you need to just restart the environment

$ docker-machine restart default      # Restart the environment
$ eval $(docker-machine env default)  # Refresh your environment settings

-------------------
4) to check the list of images installed
docker images

5) to run a container from the image (nginx, a reverse proxy, load balancer server for example)
-------------------
docker run kitematic/hello-world-nginx

----------------------
6) to check the list of active containers
docker ps -a to check the status all containers

Note: use doc


7) to stop the container

docker stop <<imagename>>

docker stop nostalgic_mcclintock
-----------------------
8) to remove the container and leave the image as is

docker rm <<containerId>>

 docker rm 2b

----------------------------
9) to run the container on a specific port in daemon mode for example, 

 docker run -d -p 5000:80 kitematic/hello-world-nginx

Here, 5000 is external port and 80 is internal port

10) You can now try launching the instance in the browser
using 

http://192.168.99.100:5000