Docker quick start guide on Mac

Docker is an open-source project that automates the deployment of applications inside software containers. Here is Docker quick start guide on Mac.

  1. Install docker toolbox by downloading them from Docker toolbox site.
  2. Once installed open docker quick start terminal by searching it from Mac launchpad.
    mac-launchpad-docker-quick-start-terminalYou may see a new bash shell with something like this:
    ##         .
                      ## ## ##        ==
                   ## ## ## ## ##    ===
               /"""""""""""""""""\___/ ===
          ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
               \______ o           __/
                 \    \         __/
    docker is configured to use the default machine with IP
    For help getting started, check out the docs at
  3. Check docker info
    $ docker info
    Containers: 6
    Images: 18
    Server Version: 1.9.1
    Storage Driver: aufs
     Root Dir: /mnt/sda1/var/lib/docker/aufs
     Backing Filesystem: extfs
     Dirs: 30
     Dirperm1 Supported: true
    Execution Driver: native-0.2
    Logging Driver: json-file
    Kernel Version: 4.1.13-boot2docker
    Operating System: Boot2Docker 1.9.1 (TCL 6.4.1); master : cef800b - Fri Nov 20 19:33:59 UTC 2015
    CPUs: 1
    Total Memory: 1.956 GiB
    Name: default
    Debug mode (server): true
     File Descriptors: 21
     Goroutines: 38
     System Time: 2016-01-25T06:37:31.858289467Z
     EventsListeners: 0
     Init SHA1: 
     Init Path: /usr/local/bin/docker
     Docker Root Dir: /mnt/sda1/var/lib/docker
  4. Get default VM IP

    $ docker-machine ip default
  5. List all docker machines

    $ docker-machine ls
    NAME      ACTIVE   URL          STATE     URL                         SWARM   DOCKER   ERRORS
    default   *        virtualbox   Running   tcp://           v1.9.1  
  6. Download ubuntu image

    $ sudo docker pull ubuntu
    Using default tag: latest
    latest: Pulling from library/ubuntu
    Digest: sha256:457b05828bdb5dcc044d93d042863fba3f2158ae249a6db5ae3934307c757c54
    Status: Image is up to date for ubuntu:latest
  7. Run interactive shell on ubuntu image and create a container named ubuntu1

    $ docker run -it --name ubuntu1 ubuntu /bin/bash
    root@2641c6ddab9f:/# ls
    bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

    To detach tty without existing shell, use Ctrl-p + Ctrl-q. Otherwise use Ctrl-d.

    To attach it again use

    docker attach [container_id_or_name]
  8. List containers

    $ docker ps  #running containers
    $ docker ps -a  #all containers
  9. Start/stop containers
    $ docker stop [container_id_or_name]  # stop container
    $ docker rm [container_id_or_name]  # remove container
    $ docker start [container_id_or_name] #start container
    $ docker restart [container_id_or_name] #restart container
    $ docker kill [container_id_or_name] #kill signal to container
  10. Print docker env variables

    $ docker-machine env default
    export DOCKER_TLS_VERIFY="1"
    export DOCKER_HOST="tcp://"
    export DOCKER_CERT_PATH="/Users/user1/.docker/machine/machines/default"
    export DOCKER_MACHINE_NAME="default"
    # Run this command to configure your shell: 
    # eval $(docker-machine env default)

    Note that you can run the following from any shell terminal to setup docker env (instead of running docker quick start terminal)

    $ eval $(docker-machine env default)
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments