一促王、加速器配置
加速器配置(每個(gè)用戶的配置不同):
首先需要到daocloud 中注冊(cè)獲得一個(gè)加速配置的腳本
[root@localhost ~]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://32399471.m.daocloud.io
docker version >= 1.12
{"registry-mirrors": ["http://32399471.m.daocloud.io"]}
Success.
You need to restart docker to take effect: sudo systemctl restart docker
二访诱、docker基礎(chǔ)常用的知識(shí)點(diǎn)
1.獲取鏡像
docker pull [選項(xiàng)] [Docker Registry地址]<倉(cāng)庫(kù)名>:<標(biāo)簽>
如果不指定registry地址颜曾、標(biāo)簽 會(huì)默認(rèn)使用官方地址,最新版本
[root@localhost ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
bc95e04b23c0: Pull complete
110767c6efff: Pull complete
f081e0c4df75: Pull complete
Digest: sha256:ecc3e131cf16c20d9f4559b03ef3ffcd3b5d01a1559c7bb9d3070890f3fca061
Status: Downloaded newer image for nginx:latest
2.列出所下載的鏡像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 1e5ab59102ce 9 hours ago 108MB
3.運(yùn)行容器
docker run --name webserver -d -p 81:80 nginx:latest
4.Dockerfile 案例
FROM debian:jessie
RUN buildDeps='gcc libc6-dev make' \
&& apt-get update \
&& apt-get install -y $buildDeps \
&& wget -O redis.tar.gz "http://download.redis.io/releases/redis-3.2.5.tar.gz" \
&& mkdir -p /usr/src/redis \
&& tar -xzf redis.tar.gz -C /usr/src/redis \
&& make -C /usr/src/redis \
&& make -C /usr/src/redis install \
&& rm -rf /var/lib/apt/lists/* \
&& rm redis.tar.gz \
&& rm -r /usr/src/redis \
&& apt-get purge -y --auto-remove $buildDeps
5.查看所有的容器運(yùn)行狀態(tài)
[root@watson-docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cdf2d059cf44 nginx "nginx -g 'daemon ..." 16 hours ago Up 16 hours 80/tcp temp_nginx
6bba12865819 nginx:V2 "nginx -g 'daemon ..." 17 hours ago Up 17 hours 0.0.0.0:8000->80/tcp web
94e24c4c98cf nginx:latest "nginx -g 'daemon ..." 17 hours ago Up 17 hours 0.0.0.0:8001->80/tcp test_nginx
6.查看容器的端口映射
[root@watson-docker ~]# docker port test_nginx
80/tcp -> 0.0.0.0:8001
7.獲取容器的所有的變量
[root@watson-docker ~]# docker inspect test_nginx
[
{
"Id": "94e24c4c98cfd574f916a7c351709333299fe22f57d0a0409947a5c3c6947536",
"Created": "2017-10-12T08:47:13.525189618Z",
"Path": "nginx",
"Args": [
"-g",
"daemon off;"
......
8.進(jìn)入容器內(nèi)部[-i 表示啟用交互模式,-t表示啟用一個(gè)終端壕翩,-d 表示在后臺(tái)運(yùn)行]
[root@watson-docker ~]# docker exec -it test_nginx bash
root@94e24c4c98cf:/#
9.容器互聯(lián)
使用 --link 參數(shù)可以讓容器之間安全的進(jìn)行交互。[--link 參數(shù)的格式為 --link name:alias 傅寡,其中 name 是要鏈接的容器的名稱放妈, alias 是這個(gè)連接的別名]
①先創(chuàng)建一個(gè)db容器
[root@watson-docker ~]# docker run --name db -d training/postgres
55745b7b7707e53d446222049d3e697abfa90f7d4edf6253428c7e47aa216b3f
②創(chuàng)建一個(gè)web服務(wù),連接到db容器(并未指定外部的端口映射)
[root@watson-docker ~]# docker run -itd --name web --link db:xx nginx:V2
31ae5af08109e14d52e080c548f7d942f363b0b40e61312036a099c63ccb4543
③查看db荐操、web并未有對(duì)外的端口映射
[root@localhost ~]# docker port web
[root@localhost ~]# docker port db
10.指定容器的主機(jī)名芜抒、dns
[root@localhost ~]# docker run -itd -h test01 --name test-web --dns=192.168.6.6 nginx:latest
11.設(shè)定容器訪問(wèn)外部網(wǎng)絡(luò)
設(shè)置:net.ipv4.ip_forward = 1
- Docker 底層的核心技術(shù)包括
- Linux 上的命名空間(Namespaces)
- 控制組(Control groups):資源控制
- Union 文件系統(tǒng)(Union file systems):一種分層、輕量級(jí)并且高性能的文件系統(tǒng)
容器格式(Container format)