标签:创建 iso idt def viso files service set 国外
欢迎来到 来到大浪涛天的博客 !
Docker 是 dotcloud 公司开源的一款产品 dotcloud 是 2010 年新成立的一家公司,主要基于 PAAS ( Platfrom as a Service ) 平台为开发者提供服务。2013 年 10 月 dotcloud 公司改名为 Docker 股份 有限公司。
1. linux container是一种内核级别的虚拟化技术,可以提供轻量级的虚拟化技术,用于隔离进程和资源
2. docker是PAAS提供商dotcloud开源基于LXC的高级容器引擎,源代码托管在github上,基于go语言并遵从apache2.0协议开源
3. docker是设想交付环境如海运,OS如同货轮,在OS上的每一个应用件都代表一个个集装箱,用户可以通过标准化手段自由组装环境。
1. docker 仓库:https://hub.docker.com
2. docker 的自身组件
docker client:docker客户端
docker server: docker的daemon的重要组成部分,接受用户client端发出的请求,并按照相应的路由规则实现路由分发
docker 的镜像:docker的镜像运行之后就变成了容器(docker run)
1. script 安装
1) yum update -y
2) curl -sSL https://get.docker.com/ | sh
3) systemctl start docker
4) systemctl enable docker
5) docker run hello-world
2. YUM 安装
1) yum update
2) cat >/etc/yum.repos.d/docker.repo <<-EOF
[dockerrepo]
name=Docker Repository baseurl=https://yum.dockerproject.org/repo/main/centos/7 enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg EOF
yum install docker
3) yum install -y docker
4) systemctl start docker
5) systemctl enable docker
6) docker run hello-world
3. RPM包安装(推荐)
1) yum update -y
2) https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
docker-ce以及docker-selinux这两个包
3)mkdir /tools && cd /tools
4) scp docker* root@10.211.55.200:/tools
5) yum install -y docker*
6) systemctl start docker
7) systemctl enable docker
8) docker run hello-world
因为每次运行docker run,如果本地没有该镜像,都会自动的从hub.docker.com下载而来,而hub.docker的官方站点在国外,所以下载镜像很慢,因此就要用到docker的加速,比如阿里的,配置完成后,我们发请求到阿里服务器,阿里服务器再请求hub.docker,然后通过阿里服务器返回给客户端,这样通过阿里的代理可以比较快速的下载镜像到本地。
1. cp /lib/systemd/system/docker.service /etc/systemd/system/docker.service
2. chmod 777 /etc/systemd/system/docker.service
3. vim /etc/systemd/system/docker.service
4. ExecStart=/usr/bin/dockerd-current --registry-mirror=https://kfp63jaj.mirror.aliyuncs.com
5. [root@dockerhub tools]# systemctl daemon-reload
6. [root@dockerhub tools]# systemctl restart docker
7. [root@dockerhub tools]# ps -ef |grep docker 可以看到docker已经启用了加速配置
[root@docker tools]# docker run --name db --env MYSQL_ROOT_PASSWORD=admin123 -d mariadb
[root@docker tools]# docker run --name wordpress --link db:mysql -p 8000:80 -d wordpress
[root@docker tools]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
449d30665b60 wordpress "docker-entrypoint..." 4 seconds ago Up 4 seconds 0.0.0.0:8000->80/tcp wordpress
95ae537a23e0 mariadb "docker-entrypoint..." About a minute ago Up About a minute 3306/tcp
docker + command + 参数
1. docker info 查看docker守护进程的资源设置
2. docker search nginx docker仓库的查询
3. docker pull nginx 从docker 仓库的下载镜像
4. docker images docker 本地镜像查询
5. docker rmi 从本地删除镜像
6. docker ps 容器的查询
7. docker run 容器的创建启动
8. docker start/stop 容器的开启与关闭
# Docker 指令除了单条使用外,还支持赋值、解析变量、嵌套使用,如:
[root@docker tools]# docker stop $(docker ps -q)
449d30665b60
95ae537a23e0
[root@docker tools]# docker ps
CONTAINER ID IMAGE COMMAND
[root@docker tools]# docker start $(docker ps -a -q)
449d30665b60
95ae537a23e0
[root@docker tools]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
449d30665b60 wordpress "docker-entrypoint..." 13 minutes ago Up 4 seconds 0.0.0.0:8000->80/tcp wordpress
95ae537a23e0 mariadb "docker-entrypoint..." 14 minutes ago Up 12 seconds 3306/tcp db
每一个容器被创建以后都会被分配一个唯一的标识CONTAINER ID,后续对容器的启动,停止,修改删除,等所有的操作都是通过CONTAINER ID来完成。
docker ps --no-trunc
docker stop/start container-name
docker inspect container-name
docker logs container-name
docker stats container-name
docker stats
docker exec container-name ls -a /
docker exec -it container-name /bin/bash
docker run是镜像变成容器的重要工具,后面可以加一些参数可以注入到容器里,如
--restart=always
[root@docker tools]# docker run --name db --restart=always -d mariad
-h x.x.x.x
[root@docker tools]# docker run --name db -h testdb --env MYSQL_ROOT_PASSWORD=admin123 -d mariadb
c3fae40c1d26b50e8736e3cf57f40d63a9342afd38934b31049301e5e622332e
[root@docker tools]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c3fae40c1d26 mariadb "docker-entrypoint..." 4 seconds ago Up 3 seconds 3306/tcp db
[root@docker tools]#
[root@docker tools]#
[root@docker tools]# docker exec db hostname
testdb
[root@docker tools]#
--dns x.x.x.x
docker run --name test --dns 10.211.55.1 -p 2200:22 -d b2ab0ed558bb
[root@docker ~]# docker exec test cat /etc/resolv.conf
nameserver 10.211.55.1
--add-host hostname:ip
[root@docker ~]# docker run --add-host test:10.211.55.1 -d b2ab0ed558bb
[root@docker ~]# docker exec 44b40c310164 grep "test" /etc/hosts
10.211.55.1 test
[root@docker ~]# docker rm -f $(docker ps -q)
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
07bb58bd70af hub.c.163.com/public/centos:6.7-tools "/usr/bin/supervisord" 7 seconds ago Up 6 seconds 22/tcp test
[root@docker ~]# docker stop test
test
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
官方站点,比较慢
curl -L https://github.com/docker/compose/releases/download/1.14.0/docker-compose-`uname -s`- `uname -m` > /usr/local/bin/docker-compose
第三方站点,高速下载
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose 或者
curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
echo "PATH=$PATH:/usr/local/bin" >>/etc/profile
source /etc/profile
docker-compose --version
[root@docker dock]# docker-compose -f wordpress.yaml up -d
Creating network "dock_default" with the default driver
Creating dock_db_1 ... done
Creating dock_wordpress_1 ... done
[root@docker dock]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------
dock_db_1 docker-entrypoint.sh mysqld Up 3306/tcp
dock_wordpress_1 docker-entrypoint.sh apach ... Up 0.0.0.0:8000->80/tcp
[root@docker dock]# docker-compose -f wordpress.yaml stop
Stopping dock_wordpress_1 ... done
Stopping dock_db_1 ... done
[root@docker dock]# docker-compose ps
Name Command State Ports
------------------------------------------------------------------
dock_db_1 docker-entrypoint.sh mysqld Exit 0
dock_wordpress_1 docker-entrypoint.sh apach ... Exit 0
[root@docker dock]# docker-compose restart
Restarting dock_wordpress_1 ... done
Restarting dock_db_1 ... done
[root@docker dock]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------
dock_db_1 docker-entrypoint.sh mysqld Up 3306/tcp
dock_wordpress_1 docker-entrypoint.sh apach ... Up 0.0.0.0:8000->80/tcp
[root@docker dock]# docker-compose logs db
Attaching to dock_db_1
db_1 | 2020-10-16 21:22:21+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.6+maria~focal started.
db_1 | 2020-10-16 21:22:22+00:00 [Note] [Entrypoint]: Switching to dedicated user ‘mysql‘
db_1 | 2020-10-16 21:22:22+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.6+maria~focal started.
db_1 | 2020-10-16 21:22:22+00:00 [Note] [Entrypoint]: Initializing database files
db_1 |
[root@docker dock]# docker-compose config -q
[root@docker dock]# docker-compose config
services:
db:
environment:
MYSQL_DATABASE: wordpress
MYSQL_PASSWORD: admin123
MYSQL_ROOT_PASSWORD: admin123
MYSQL_USER: wordpress
image: mariadb:latest
restart: always
wordpress:
depends_on:
- db
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: admin123
WORDPRESS_DB_USER: wordpress
image: wordpress:latest
ports:
- 8000:80/tcp
restart: always
version: ‘2.0‘
[root@docker dock]# docker-compose stop wordpress
Stopping dock_wordpress_1 ... done
[root@docker dock]# docker-compose start wordpress
Starting wordpress ... done
[root@docker dock]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------
dock_db_1 docker-entrypoint.sh mysqld Up 3306/tcp
dock_wordpress_1 docker-entrypoint.sh apach ... Up 0.0.0.0:8000->80/tcp
[root@docker dock]# docker-compose stop wordpress db
Stopping dock_wordpress_1 ... done
Stopping dock_db_1 ... done
[root@docker dock]# docker-compose -f wordpress.yaml up -d
Starting dock_db_1 ... done
Starting dock_wordpress_1 ... done
[root@docker dock]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------
dock_db_1 docker-entrypoint.sh mysqld Up 3306/tcp
dock_wordpress_1 docker-entrypoint.sh apach ... Up 0.0.0.0:8000->80/tcp
标签:创建 iso idt def viso files service set 国外
原文地址:https://www.cnblogs.com/chacha51/p/13832497.html