Differences between revisions 2 and 3
Revision 2 as of 2015-08-20 18:47:40
Size: 7212
Editor: twotwo
Comment: 从以安装V1.7的说明更新为安装V1.8的说明
Revision 3 as of 2020-02-08 22:17:30
Size: 6906
Editor: twotwo
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
See also [[Docker]]
= Get Started with Docker(Based on v1.8) =
|| See also [[Docker]] ||
= Get Started with Docker =
Line 9: Line 9:
[[https://docs.docker.com/installation/mac/|Install Docker on Mac OS X|target="_blank"]]、[[https://docs.docker.com/installation/centos/|Install Docker on CentOS|target="_blank"]]、[[https://docs.docker.com/docker/installation/windows/|Install Docker on Windows|target="_blank"]]
Line 13: Line 12:
V1.8最大的变化,非Linux的系统从安装[[https://www.docker.com/toolbox|toolbox|target="_blank"]]开始,Docker Toolbox包含了以下内容:
 * Docker Machine for running the `docker-machine` binary
 * Docker Engine for running the `docker` binary
 * Docker Compose for running the `docker-compose` binary
 * Kitematic, the Docker GUI
 * a shell preconfigured for a Docker command-line environment
 * Oracle VM VirtualBox
=== Install Docker Desktop on macOS ===
[[https://docs.docker.com/docker-for-mac/install/|Install Docker Desktop on Mac|target="_blank"]]
Line 21: Line 15:
从V1.7更新到1.8,参考[[http://docs.docker.com/installation/mac/#migrate-from-boot2docker||target="_blank"]] [[https://docs.docker.com/docker-for-mac/|Get started|target="_blank"]]
Line 23: Line 17:
原来在host输入的`boot2docker`命令被替换成了`docker-machine`,命令参考:[[https://docs.docker.com/installation/mac/#from-your-command-line|ref|target="_blank"]] === Install Docker on Ubuntu 18.04 ===
[[https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04||target="_blank"]]
Line 26: Line 21:
wget https://get.daocloud.io/toolbox/DockerToolbox-1.8.1b.pkg
##安装完成DockerToolbox-1.8.1b.pkg,直接启动Docker Quickstart Terminal
bash-3.2$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
default * virtualbox Running tcp://192.168.99.100:2376
bash-3.2$ docker run -d -P --name web nginx
c89a9312ba39268cf2a85f3bf17ab2598d45882bb2668ffb7abbfc56088e161d
bash-3.2$ docker port web
443/tcp -> 0.0.0.0:32770
80/tcp -> 0.0.0.0:32771
bash-3.2$ docker-machine ip default
192.168.99.100
bash-3.2$ curl -I 192.168.99.100:32771/
HTTP/1.1 200 OK
Server: nginx/1.9.4
Date: Thu, 20 Aug 2015 10:26:40 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 18 Aug 2015 16:09:59 GMT
Connection: keep-alive
ETag: "55d358d7-264"
Accept-Ranges: bytes
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt install docker-ce
sudo usermod -aG docker ${USER}
# https://docs.docker.com/compose/completion/
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo curl -L https://raw.githubusercontent.com/docker/compose/1.25.0/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
}}}
Line 49: Line 33:
=== Install Docker Desktop on Windows ===
[[https://docs.docker.com/docker-for-windows/install/|Install Docker Desktop on Windows|target="_blank"]]

{{{#!highlight bash numbers=disable
# 直接下载镜像
wget https://download.docker.com/win/stable/Docker%20Desktop%20Installer.exe
}}}

配置镜像

{{{#!highlight json numbers=disable
{
  "registry-mirrors": [
    "https://dockerhub.azk8s.cn",
    "https://hub-mirror.c.163.com"
  ]
}

See also Docker

Get Started with Docker

Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app)。几乎没有性能开销,可以很容易地在机器和数据中心中运行。最重要的是,他们不依赖于任何语言、框架包括系统。

1. Installation

mac_docker_host.svg

linux_docker_host.svg

win_docker_host.svg

1.1. Install Docker Desktop on macOS

Install Docker Desktop on Mac

Get started

1.2. Install Docker on Ubuntu 18.04

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

sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt install docker-ce
sudo usermod -aG docker ${USER}
# https://docs.docker.com/compose/completion/
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo curl -L https://raw.githubusercontent.com/docker/compose/1.25.0/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

1.3. Install Docker Desktop on Windows

Install Docker Desktop on Windows

# 直接下载镜像
wget https://download.docker.com/win/stable/Docker%20Desktop%20Installer.exe

配置镜像

{
  "registry-mirrors": [
    "https://dockerhub.azk8s.cn",
    "https://hub-mirror.c.163.com"
  ]
}

2. Start from Termial

#!/bin/sh

#  docker.sh
#  Start docker demeon and config local env, work for Docker V1.8
#
#  Created by liyan on 15-8-24. Replace for /Applications/Docker/Docker\ Quickstart\ Terminal.app/Contents/Resources/Scripts/start.sh
#  Copyright (c) 2015年 li3huo.com All rights reserved.

# alias docker="docker --tlsverify=false"

machine=default

if [ `docker-machine status ${machine}` != 'running' ]; then
  docker-machine start ${machine}
  # https://www.virtualbox.org/manual/ch04.html#sharedfolders --automount
  VBoxManage sharedfolder add "${machine}" --name "app" --hostpath "/opt/app" --readonly --transient
  docker-machine ssh ${machine} "sudo mkdir /opt/app;sudo mount -t vboxsf app /opt/app"
  echo "mount /opt/app on demeon"
fi

eval "$(docker-machine env ${machine})"

docker-machine status ${machine}

docker-machine ssh ${machine} "ls -l /opt/app"

2.1. docker-machine

https://docs.docker.com/installation/mac/#from-your-command-line

boot2docker

docker-machine

docker-machine description

init

create

Creates a new docker host.

up

start

Starts a stopped machine.

ssh

ssh

Runs a command or interactive ssh session on the machine.

save

-

Not applicable.

down

stop

Stops a running machine.

poweroff

stop

Stops a running machine.

reset

restart

Restarts a running machine.

config

inspect

Prints machine configuration details.

status

ls

Lists all machines and their status.

info

inspect

Displays a machine’s details.

ip

ip

Displays the machine’s ip address.

shellinit

env

Displays shell commands needed to configure your shell to interact with a machine

delete

rm

Removes a machine.

download

-

Not applicable.

upgrade

upgrade

Upgrades a machine’s Docker client to the latest stable release.

3. Example of Docker on Mac OS X

https://docs.docker.com/installation/mac/#example-of-docker-on-mac-os-x

➜  docker  docker run -d -P --name web nginx #deamon, publishes exposed ports
➜  ~  echo http://"$(boot2docker ip)":"$(docker port web |sed -n 's/80\/tcp -> 0.0.0.0:\(.*\)/\1/p')"
http://192.168.59.103:32769
➜  docker  docker stop web #docker rm web

Nginx #403: How to Use Docker on OS X: The Missing Guide

➜  site  docker run -d -P -v $HOME/docker_site:/usr/share/nginx/html --name mysite nginx
➜  ~  echo http://"$(boot2docker ip)":"$(docker port mysite |sed -n 's/80\/tcp -> 0.0.0.0:\(.*\)/\1/p')"
http://192.168.59.103:32772/
➜  docker  curl http://192.168.59.103:32779
my new site
# ssh into the boot2docker VM
➜  ~  boot2docker ssh

3.1. Dockerizing OS as Application

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

➜  docker  docker run -t -i centos /bin/bash
[root@bc155ce694ee /]# exit
exit
➜  docker  docker run centos /bin/sh -c "cat /etc/redhat-release" 
CentOS Linux release 7.1.1503 (Core)

4. Other Tools

4.1. Compose

https://docs.docker.com/compose/

➜  Docker  brew install docker-compose

Quickstart Guide: Compose and Wordpress

4.2. Fig

http://www.infoq.com/cn/articles/docker-build-development-environment-based-on-fig

Fig是Docker的开发部署工具,我们可以使用fig.yml文件来定义所有的环境,一次定义,多处使用,简单而且高效。

➜  Docker  brew install fig
...
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
🍺  /usr/local/Cellar/fig/1.3.1: 222 files, 2.7M
➜  docker  fig -v
docker-compose version: 1.3.1
CPython version: 2.7.6
OpenSSL version: OpenSSL 0.9.8zf 19 Mar 2015

5. Reference

MainWiki: Docker_Started (last edited 2020-02-08 22:17:30 by twotwo)