Public | Automated Build

Last pushed: a year ago
Short Description
Hello World Docker
Full Description

Learning Docker

Optimize the power of docker to run your applications quickly and easily

Install Docker:

```{r, engine='shell', count_lines}

install docker

sudo apt-get install -y docker.io

upgrade to latest version

echo "docker source"
sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
echo "docker release public key"
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
echo "install docker..."
sudo apt-get install -y lxc-docker

current release 1.12.1



##### Install Docker-Compose:

from repo

sudo sh -c 'wget -qO- https://github.com/docker/compose/releases/download/<VERSION>/ docker-compose-'uname -s'-'uname -m' > /usr/local/bin/docker-compose; chmod +x /usr/local/bin/docker-compose'

with python pip

sudo pip install -U docker-compose

sudo docker-compose --version



#### Command Cheat Sheet:

docker pull [-a] [boxname] # for instance: busybox, download -a all versions

box name or path location format

https:// - http:// - ftp:// - or local container absolute path

docker push <docker-id>/<imagename> # publish customized docker file to the docker hub

docker images [--no-trunc] # list installed & available containers., show full hash

docker run [--entrypoint="<command>"] [--name] [--rm] [-d] [-t] [-i] [boxname] [bash command here] # --name manual config host id, --rm remove on terminate, -d run as deamon, -t tty terminal, -i interactive stdin open...

service docker [status|start|stop] # docker deamon status

/var/log/upstart/docker.log # logs files

docker search [lookup keyword] # search of images

docker ps [-a] # list all the running containers and their properties, -a all even stopped instances

docker diff [instance-id or name] # inspect the fs for changes.

docker stop [instance-id or name] # terminate a running docker instance

docker start [instance-id or name] # resume an idle docker instance

docker attach [instance-id or name] # gather instance tty

docker pause [instance-id or name] # freeze all the execution of all the processes within that container

docker unpause [instance-id or name] # converse to pause. resume the exectution from the point where is was frozen.

delete container

docker rm [-f] [instance-id or name] 'sudo docker ps -aq --no-trunc' # remove all idle instances, -f remove also running instances

delete container image

docker rmi <docker-id>/<imagename>

docker commit [instance-id or name] [new instance-name or id] # committing new image from container (its strongly recommanded to perform it when instance is idle.

docker logs [instance-id] # view the output generated by a daemon container

docker build [-t reponame] [-f dockerfile] [path to dockerfile directory] # build docker image from Dockerfile specs, -t="docker-id/dockerimage"

docker tag [instance-id] [image-name[:image-tag]] # assign or update image name, optional tag name

docker history # display docker image layers.



#### Dockerfile Cheatsheet 

```bash


FROM [repository:version] #  choosing the base image selection

CMD [command] # command after image start

Docker Container Networking


# lookup host docker network interface private ip
ifconfig docker0 # 172.17.0.1 [172.17.x.x]

# lookup container instance private ip
sudo docker run -i -t ubuntu /bin/bash # && ifconfig

# if ifconfig not installed:
apt-get update
apt-get install net-tools
ifconfig # the container has @ 172.17.0.2

# lookup container instance private ip, when the container use -d <detached mode>
docker inspect --format='{{.NetworkSettings.IPAddress}}' <container-id>

Docker Compose


docker-compose -f <filepath|default:docker-compose.yml> -p <projectname|default:dirname>

### docker-compose cli 
build:  This builds or rebuilds services
kill:   This kills containers
logs:   This displays the output from the containers
port:   This prints the public port for a port binding
ps:     This lists the containers
pull:   This pulls the service images
rm:     This removes the stopped containers
run:    This runs a one-off command
scale:  This sets a number of containers for a service
start:  This starts services
stop:   This stops services
up:     This creates and starts containers


### docker-compose tags format
<service>: name of the service
    key:value, ...  # compulsory either image or build per service.

### docker-compose keys
image: <tag>|<imageID>           
build: <path-to-Dockerfile>
command: <cmd> override default cmd
links: link containers in another serivce <service-name>
external_links: link with external service or means ...
ports: exposes ports >> <HOST_port>:<CONTAINER_port>
expose: exposes ports >> <port>
volumes: mount host paths as volumes <path>
volumes_from: mount all volumes form another container <service-name>
environment: <k=v>  either array or dict
env_file: adds env_vals to a file <file_path>
extends: extends to another service.
net: networking mode, same effect as --net 
pid: enables PID space sharing between host and containers
dns: set custom dns servers
cap_add: add capability to containers
cap_drop: disable capability from containers
dns_search: custom dns search servers
working_dir: change default working dir inner container
entrypoint: overrides the default entrypoint
user: set the default user
hostname: set container's host name
domainname: set domain name
mem_limit: this limits ram mem
priviledged: gives extended priviledges
restart: this sets the restart policy of the container
stdin_open: enables the standard input facility
tty: enables text based control such as terminal
cpu_shares: set cpu shares (relative weight) %

Task Lists

  • [x] task 1: docker hello world
  • [x] task 2: docker docker-compose.yml
  • [ ] task x
  • [x] John Gay says infinity is a number :+1: .

Getting started with docker

  • Key concepts:

    • VMs vs Containers

      • VM represents harware-level virtualization (heavyweight), limited performance, fully isolated and hence more secure
      • Cont. represents operating system virtualization (lightweight), native performance, process-level isolation and hence less secure
    • Docker Engine: produce, monitor and manages multiple containers

    • Docker Image: unit of software entity that is embodied within an isolated module, which can be stacked with parent (root image, OS) to form a composite.

    • Docker Layer: can be represented as r-only or rw images. however the top layer of a container is always the rw layer, which hosts a Docker container.

    • Docker Container: rw layer == container layer, Docker pulls the required image and its parent image. trough all the parent images until it reaches the base image.

    • Docker Registry: is a place where the docker images can be stored in order to be publicly found, accessed...

    • Docker Repository: is a namespace that is used for storing Docker image.

    • Docker Hub Registry: docker pull subcommand is programmed to lookup by default images available in the public docker registry (index.docker.io)

    • Service Computing (Orchestration): manner to produce and sustain highly robust and resilient services.

    • Microservice Architecture: is an architectural concept that aims to decouple a software solution by decomposing its functionality into a pool of discrete services.

  • Acronims (order by name asc):

    • AIX: Advanced Interactive Executive
    • AUFS: Another Union File System
    • DNAT: Destination NAT
    • IANA: Internet Assigned Numbers Authority # docker default 2375
    • FreeBSD: Free Berkley Software Distribution
    • LXC: Linux Containers
    • NAT: Network Address Translation
    • SC: Service Computing
    • VEs: Virtual Environments
    • VPSs: Virtual Private Servers
    • WPARs: Workload Partitions
    • YAML: YAML Ain't Markup Language
Docker Pull Command
Owner
chenglongzq
Source Repository

Comments (0)