1. Docker是什么
Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源。Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),容器性能开销极低。
特点:像虚拟机但是更加依赖host machine,比之开销更低,移植性更好
2. Docker的Ubuntu配置
一个很好的教程 https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04
需求:64bit Ubuntu + 内核>3.10 (用 uname -r 检查) + non-root user + sudo 特权
安装步骤:
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 $(lsb_release -cs) stable"
3. update the package database with the Docker packages from the newly added repo:
sudo apt-get update
4. Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo:
apt-cache policy docker-ce
得到类似下图的输出
docker-ce:
Installed: (none)
Candidate: 17.03.1~ce-0~ubuntu-xenial
Version table:
17.03.1~ce-0~ubuntu-xenial 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
17.03.0~ce-0~ubuntu-xenial 500
500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
5. install
安装docker社区版本(CE)
sudo apt-get install -y docker-ce
Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it's running:
sudo systemctl status docker
得到类似下图的输出
Output
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2016-05-01 06:53:52 CDT; 1 weeks 3 days ago
Docs: https://docs.docker.com
Main PID: 749 (docker)
Installing Docker now gives you not just the Docker service (daemon) but also the docker command line utility, or the Docker client. We'll explore how to use the docker command later in this tutorial.
$ sudo systemctl enable docker
$ sudo systemctl start docker
$ docker run hello-world
默认情况下, docker 命令会使用 Unix socket 与 Docker 引擎通讯。而只有 root 用户和docker 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑,一般 Linux 系统上不会直接使用 root 用户。因此,更好地做法是将需要使用 docker 的用户加入 docker用户组。
0. 创建用户组(此处为docker)
$ sudo groupadd docker
1. add your username to the docker group:
sudo usermod -aG docker ${USER}
To apply the new group membership, you can log out of the server and back in, or you can type the following:
su - ${USER}
You will be prompted to enter your user's password to continue. Afterwards, you can confirm that your user is now added to the docker group by typing:
id -nG
Output
sudo usermod -aG docker username
The rest of this article assumes you are running the docker command as a user in the docker user group. If you choose not to, please prepend the commands with sudo.
docker
As of Docker 1.11.1, the complete list of available subcommands includes:
Output
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on a container or image
kill Kill a running container
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
network Manage Docker networks
pause Pause all processes within a container
port List port mappings or a specific mapping for the CONTAINER
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart a container
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop a running container
tag Tag an image into a repository
top Display the running processes of a container
unpause Unpause all processes within a container
update Update configuration of one or more containers
version Show the Docker version information
volume Manage Docker volumes
wait Block until a container stops, then print its exit code
0. 其他问题:
a. 使用docker出现timeout错误
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pulling fs layer
docker: error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net/registry-v2/docker/registry/v2/blobs/sha256/48/48b5124b2768d2b917edcb640435044a97967015485e812545546cbed5cf0233/data?Expires=1490975964&Signature=OUmibCvoXIlDlmt-GF187GDtJySfLIHJdgfs~GTyzARgOPaVYLfU8kLKKFnS3NczD39-PtCdTxEMKmE0IigxpsmDQimidTyuqOIlac-wDGhrLPveHoKIUYZ9QP9hzzAvRyhci9wrsWJJkrsOz3ITUaNRDM3z9xHyyQi07WQGLiQ_&Key-Pair-Id=APKAJECH5M7VWIS5YZ6Q: dial tcp: lookup dseasb33srnrn.cloudfront.net on 192.168.65.1:53: read udp 192.168.65.2:55172->192.168.65.1:53: i/o timeout.
See 'docker run --help'.
Solu: may be you are behind a firewall/proxy server. i was also behind my office firewall so i tried below steps which resolved this issue.
For setting up proxy for docker, please do the following:
(1). Create a systemd drop-in directory for the docker service:
$ mkdir -p /etc/systemd/system/docker.service.d
$ vim /etc/systemd/system/docker.service.d/http-proxy.conf
Then add below content with proxy settings with it,注意将addr和port换成代理的host和port
[Service]
Environment="HTTP_PROXY=http://:/"
(2). For HTTPS proxy server:
$ vim /etc/systemd/system/docker.service.d/https-proxy.conf
Then add below content with proxy settings with it
[Service]
Environment="HTTPS_PROXY=https://:/"
(3). Flush changes execute: $ sudo systemctl daemon-reload
(5). Verify that the configuration has been loaded: $ systemctl show --property=Environment docker