Docker is an open-source project that automates the deployment of applications inside software containers. Here is Docker quick start guide on Mac.
- Install docker toolbox by downloading them from Docker toolbox site.
-
Once installed open docker quick start terminal by searching it from Mac launchpad.
You may see a new bash shell with something like this:
## . ## ## ## == ## ## ## ## ## === /"""""""""""""""""\___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\_______/ docker is configured to use the default machine with IP 192.168.99.100 For help getting started, check out the docs at https://docs.docker.com $
-
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 ID: FESO:CVJC:IZ2V:XTMM:HHCT:AWBE:OUFA:WTCS:6VOZ:IT35:QQR3:RTNW 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 Labels: provider=virtualbox
-
Get default VM IP
$ docker-machine ip default 192.168.99.100
-
List all docker machines
$ docker-machine ls NAME ACTIVE URL STATE URL SWARM DOCKER ERRORS default * virtualbox Running tcp://192.168.99.100:2376 v1.9.1
-
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
-
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 useCtrl-d
.To attach it again use
docker attach [container_id_or_name]
-
List containers
$ docker ps #running containers $ docker ps -a #all containers
- 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
-
Print docker env variables
$ docker-machine env default export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.100:2376" 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)