Docker

From 太極
Jump to navigation Jump to search

Official web page http://docker.io

Installation

Ubuntu

https://docs.docker.com/installation/ubuntulinux

Windows

  • Windows. It will install Boot2Docker management tool with ISO, Virtualbox and MYSYS-git UNIX tools.
  • If the installer detects a version of VirtualBox installed, the VirtualBox checkbox will not be checked by default (Windows OS). The VirtualBox cannot be used anymore after updating my VB from 4.3.18 to 4.3.20.
Error in supR3HardenedWinReSpawn

The error may be related to Windows update.

The VB installation messed up. At the end I switch to VMware player. I cannot test Windows's Docker on my Windows machine.

Usage

Basics and docs

https://docs.docker.com/articles/basics/

Note that we need sudo is needed unless it is on a Mac OS.

If docker cannot find an image, it will try to pull it from its repository.

$ sudo docker run -it ubuntu /bin/bash
Unable to find image 'ubuntu' locally
Pulling repository ubuntu
04c5d3b7b065: Download complete 
511136ea3c5a: Download complete 
c7b7c6419568: Download complete 
70c8faa62a44: Download complete 
d735006ad9c1: Download complete 
root@ec83b3ac878d:/# 

A brief intro to docker virtualization

docker search --help
docker search redis
docker search -s 100 redis
docker pull --help
docker pull ubuntu # download all versions of ubuntu
docker images    # available local container images
docker pull centos:latest
docker run --help
cat /etc/issue   # look at the current distr name before running docker
docker run -it centos:latest /bin/bash
                 # create a container & execute as a sudo

cat /etc/redhat-release
yum
cd /home
touch temp.txt
ls
exit

docker ps   # current running processes
docker ps -a # show all processes including closed
docker restart c85850ed0e13
docker ps   # container c85850ed0e13 is running
docker attach c85850ed0e13 # log into the system

ls /home
exit

docker ps -a
docker rm c85850ed0e13 # delete the container

Dockerizing Applications

$ sudo docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
$ sudo docker ps -l
$ sudo docker logs insane_babbage
$ sudo docker stop insane_babbage
$ sudo docker ps

The -d flag tells Docker to run the container and put it in the background, to daemonize it.

Web Application/Work with containers

https://docs.docker.com/userguide/usingdocker/

$ sudo docker run -d -P training/webapp python app.py
$ sudo docker run -d -p 5000:5000 training/webapp python app.py
$ sudo docker ps   # find the NAME from the last column
                   # In this case, it is called 'nostalgic_morse'
$ sudo docker port nostalgic_morse 5000
$ sudo docker logs -f nostalgic_morse
$ sudo docker top nostalgic_morse
$ sudo docker stop nostalgic_morse
$ sudo docker ps -l
$ sudo docker start nostalgic_morse
$ sudo docker stop nostalgic_morse
$ sudo docker rm nostalgic_morse

Note: Always remember that deleting a container is final!

Work with container images

https://docs.docker.com/userguide/dockerimages/

$ sudo docker search sinatra
$ sudo docker pull training/sinatra
$ sudo docker run -t -i training/sinatra /bin/bash
$ sudo docker commit -m="Added json gem" -a="Kate Smith" 0b2616b0e5a8 ouruser/sinatra:v2
$ sudo docker images

$ mkdir sinatra
$ cd sinatra
$ touch Dockerfile
$ sudo docker build -t="ouruser/sinatra:v2" .
$ sudo docker push ouruser/sinatra
$ sudo docker rmi training/sinatra

Link containers together

https://docs.docker.com/userguide/dockerlinks/

Manage data in containers

https://docs.docker.com/userguide/dockervolumes/

Working with Docker hub

https://docs.docker.com/userguide/dockerrepos/

Misc

Access the internet from the container

Run the container with the '--net=host' option

sudo docker run --net=host -it ubuntu /bin/bash

Use with R