docker install and configure

迅800發表於2017-07-26

docker install and configure


概述

Docker系統有兩個程式:docker服務端和docker客戶端

ubuntu install docker
文件 https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04

Step 1 — Installing Docker

Update apt and add the key and repo
$sudo apt-get update

$sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
root#add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$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-ce

install Docker:
$sudo apt-get install -y docker-ce

Check that it's running:
$sudo systemctl status docker

Step 2 — Executing the Docker Command Without Sudo (Optional)

add your username to the docker group:
$sudo usermod -aG docker ${USER}

$su - ${USER}

$id -nG

$sudo usermod -aG docker username

Step 3 — Using the Docker Command

To view all available subcommands, type:
$docker

To view the switches available to a specific command, type:
$docker docker-subcommand --help

To view system-wide information about Docker, use:
$docker info

Step 4 — Working with Docker Images

$docker run hello-world

docker create self images

2. 使用Dockerfile
2.1建立映象所在的資料夾和Dockerfile檔案
$mkdir sinatra
$cd sinatra
$touch Dockerfile

2.2在Dockerfile檔案中寫入指令,沒一條指令都會更新映象的資訊例如:
-># This is a comment
->FROM ubuntu:14.04
->MAINTAINER Kate Smith ksmith@example.com
->RUN apt-get update && apt-get install -y ruby ruby-dev
->RUN gem install sinatra

格式說明:
每行命令都是以 INSTRUCTION statement 形式,就是命令+ 清單的模式。命令要大寫,“#”是註解。
FROM 命令是告訴docker 我們的映象什麼。
MAINTAINER 是描述 映象的建立人。
RUN 命令是在映象內部執行。就是說他後面的命令應該是針對映象可以執行的命令。

2.3建立映象
命令:docker build -t ouruser/sinatra:v2 .
docker build 是docker建立映象的命令
-t 是標識新建的映象屬於 ouruser的
sinatra是倉庫的名稱
:v2 是tag
“.”是用來指明 我們的使用的Dockerfile檔案當前目錄的

2.4建立完成後,從映象建立容器
$docker run -t -i ouruser/sinatra:v2 /bin/bash

附1

檢查docker的版本
$docker version

Docker官方網站專門有一個頁面來儲存所有可用的映象,網址是:index.docker.io
命令列的格式為:
$docker search 映象名字

通過docker命令下載tutorial映象:
$docker pull learn/tutorial

在docker容器中執行hello world!
$docker run learn/tutorial echo "hello word"

在容器中安裝新的程式, 一個簡單的程式(ping)
$docker run learn/tutorial apt-get install -y ping

獲得安裝完ping命令之後容器的id
$docker ps -l

檢查執行中的映象
$docker ps

檢視詳細的關於某一個容器的資訊
$docker inspect 698

儲存對容器的修改
$docker commit 698 learn/ping

執行新的映象
$docker run lean/ping ping www.google.com

釋出自己的映象
$docker push learn/ping

附2
文件 http://www.jianshu.com/p/3384e342502b

sudo docker run -d --name env_php7_coober -v /var/www:/home/coober/www roydejong/php7-xdebug

docker inspect env_php7_coober | grep "IPAddress"

docker exec -it env_php7_coober /bin/bash

sudo docker cp env_php7_coober:/etc/php/7.0/fpm/pool.d/www.conf ./

sudo docker cp  ./www.conf env_php7_coober:/etc/php/7.0/fpm/pool.d/www.conf

supervisor安裝配置與使用

伺服器啟停
sudo /etc/init.d/supervisord {start|stop|status|restart|reload|force-reload|condrestart}

可以通過supervisorctl檢視管理監控的程式情況:
supervisor>help
supervisor>help stop
supervisor> stop publisher_for_summary
supervisor> start publisher_for_summary
supervisor> start all
supervisor> stop all
supervisor> status

相關文章