Skip to content

DockerGuidance

李志强 edited this page Jun 26, 2017 · 3 revisions

Docker

Install docker latest version

Do not install docker.io! It is not the latest docker version, and it may be has bugs at mesos and kubernetes application.
Follow this steps to install docker latest version.

  • first, let's update the package database:
    sudo apt-get update

  • Now let's install Docker. Add the GPG key for the official Docker repository to the system:

sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
  • Add the Docker repository to APT sources:
sudo apt-add-repository 'deb https://apt.dockerproject.org/repo ubuntu-xenial main'
  • Update the package database with the Docker packages from the newly added repo:
sudo apt-get update
  • Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo:
apt-cache policy docker-engine
  • Finally, install Docker:
sudo apt-get install -y docker-engine

Key components

  • docker client

  • docker server (daemon)
    details

  • image (system images)

  • container (carrier running images, to make the applications isolated from outside)

  • registry (docker hub (docker.io), gcr.io, private registry)

Docker command

  • docker info

  • docker version

  • docker help

  • docker logs

  • docker search

  • docker pull

  • docker images

  • docker rmi

  • docker inspect

  • docker run

  • docker stop

  • docker start

  • docke ps -a

  • docker rm

  • docker exec / docker attach

  • docker commit

  • docker save

Dockerfile: Script for building images

FROM ubuntu:latest

MAINTAINER xuntian "[email protected]"

RUN apt-get -y update && apt-get -y install nginx && apt-get clean && rm -rf /var/lib/apt/lists/*

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
  • Run nginx image
docker run -dti -p 80 xuntian/mynginxtest  
docker run -dti -p 80 -v /root/nginx/www:/var/www/html xuntian/mynginxtest  

Dcoekr Registry

details

Docker daemon

  • connect remote docker daemon
export DOCKER_HOST="tcp://121.14.117.229:2375"