1 Star 0 Fork 0

gitfeige/Docker

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

Docker解决什么问题?

解决了运行环境和配置问题软件容器,方便做持续集成并有助于整体发布的容器虚拟化技术。

开发/运维(DevOps)一次构建、随处运行

  1. 更快速的应用交付和部署
  2. 更便捷的升级和扩缩容
  3. 更简单的系统运维
  4. 更高效的计算资源利用

下载地址:

docker官网:http://www.docker.com

docker中文网站:https://www.docker-cn.com/

Docker Hub官网: https://hub.docker.com/

Docker的基本组成:

  • 镜像(image)
  • 容器(container)
  • 仓库(repository)

安装Docker:

一、CentOS6安装Docker

1、安装Docker:

yum install -y epel-release
yum install -y docker-io

2、安装后的配置文件:

/etc/sysconfig/docker

3、启动Docker后台服务:

service docker start

4、验证Docker版本

docker version

二、CentOS7安装Docker

1、启动docker

yum -y install gcc
yum -y install gcc-c++

2、卸载旧版本

yum -y remove docker docker-common docker-selinux docker-engine

3、安装需要的软件包

yum install -y yum-utils device-mapper-persistent-data lvm2

4、设置stable镜像仓库

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

5、更新yum软件包索引

yum makecache fast

6、安装DOCKER CE

yum -y install docker-ce

7、启动docker

systemctl start docker

8、测试docker

docker version
docker run hello-world

9、配置镜像加速

mkdir -p /etc/docker
vim  /etc/docker/daemon.json
systemctl daemon-reload
systemctl restart docker

10、卸载

systemctl stop docker 
yum -y remove docker-ce
rm -rf /var/lib/docker

常用命令:

一、帮助命令

docker version
docker info
docker --help

二、镜像命令

1、镜像管理
docker images
-a :列出本地所有的镜像(含中间映像层)
-q :只显示镜像ID
--digests :显示镜像的摘要信息
--no-trunc :显示完整的镜像信息
2、搜索镜像
docker search 某个XXX镜像名字
docker search [OPTIONS] 镜像名字
--no-trunc : 显示完整的镜像描述
-s : 列出收藏数不小于指定值的镜像
--automated : 只列出 automated build类型的镜像
3、下载镜像
docker pull 某个XXX镜像名字
docker pull 镜像名字[:TAG]
4、删除镜像

删除单个

docker rmi  -f 镜像ID

删除多个

docker rmi -f 镜像名1:TAG 镜像名2:TAG 

删除全部--小心使用哈

docker rmi -f $(docker images -qa)
5、容器命令

总体步骤

  1. 搜索镜像

  2. 拉取镜像

  3. 查看镜像

  4. 启动镜像

  5. 停止容器

  6. 移除容器

新建并启动容器

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

docker run -it -p 8080:8080 tomcat

-p:主机端口:docker容器端口
-P:随机分配端口
-i:交互
-t:终端
-v:数据卷

 docker run -it -v /宿主机绝对路径目录:/容器内目录      镜像名

列出当前所有正在运行的容器

docker ps [OPTIONS]

退出容器

exit容器停止退出
ctrl+P+Q容器不停止退出

启动容器

docker start 容器ID或者容器名

重启容器

docker restart 容器ID或者容器名

停止容器

docker stop 容器ID或者容器名

强制停止容器

docker kill 容器ID或者容器名

删除已停止的容器

docker rm 容器ID
一次性删除多个容器
docker rm -f $(docker ps -a -q)
docker ps -a -q | xargs docker rm

启动守护式容器

docker run -d 容器名

查看容器日志

docker logs -f -t --tail 容器ID
*   -t 是加入时间戳
*   -f 跟随最新的日志打印
*   --tail 数字 显示最后多少条

查看容器内运行的进程

docker top 容器ID

查看容器内部细节

docker inspect 容器ID

进入正在运行的容器并以命令行交互

docker exec -it 容器ID bashShell
重新进入docker attach 容器ID
attach 直接进入容器启动命令的终端,不会启动新的进程
exec 是在容器中打开新的终端,并且可以启动新的进程

从容器内拷贝文件到主机上

docker cp  容器ID:容器内路径 目的主机路径

Docker安装常用软件

一、安装SQL

1、测试环境,安装mysql--不推荐

docker pull mysql:latest
docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root mysql

2、生成环境,挂载目录,安装mysql5.7,把数据映射到本地某个目录,容器删除重建之后,数据不会丢失。

docker pull mysql:5.7
# 创建目录
mkdir /usr/local/docker/mysql/logs
mkdir /usr/local/docker/mysql/data
mkdir /usr/local/docker/mysql/conf
touch my.cnf

[mysql]
#设置mysql客户端默认字符集
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
#mysql5.7以后的不兼容问题处理
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#允许最大连接数
max_connections=200
#服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
#创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M 
#设置时区
default-time_zone='+8:00'
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

docker run \
--name mysql5.7 -p 3306:3306 \
--privileged=true \
--restart=always \
-d \
-v /usr/local/docker/mysql/logs:/logs \
-v /usr/local/docker/mysql/data:/var/lib/mysql \
-v /usr/local/docker/mysql/conf/my.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf \
-e MYSQL_ROOT_PASSWORD=root mysql:5.7

安装Percona

docker pull percona:5.7.23
docker create --name percona -v /data/mysql-data:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root percona:5.7.23
docker start percona

二、安装NOSQL

1、安装redis

测试环境--不推荐

docker pull redis:latest 
docker run -itd --name redis -p 6379:6379 redis:latest

生产环境,

# 从官网获取redis.conf 配置文件
# bind 127.0.0.1 #注释掉这部分,这是限制redis只能本地访问
# protected-mode no #默认yes,开启保护模式,限制为本地访问
# daemonize no#默认no,改为yes意为以守护进程方式启动,可后台运行,除非kill进程(可选),改为yes会使配置文件方式启动redis失败
# dir  ./ #输入本地redis数据库存放文件夹(可选)
# appendonly yes #redis持久化(可选)

# 创建目录
mkdir /usr/redis/data:/data
# 创建配置文件
touch /usr/redis/conf/redis.conf

docker run \
-p 6379:6379 \
-v /usr/redis/data:/data \
-v /usr/redis/conf/redis.conf:/etc/redis/redis.conf \
--privileged=true \
--network=host \
--name myredis \
-d redis redis-server /etc/redis/redis.conf

2、安装mongodb

测试环境--不推荐

docker pull mongo:latest docker run -itd --name mongo -p 27017:27017 mongo

3、安装memcached

测试环境--不推荐

docker pull memcached:1.5.16 docker run --name my-memcache -p 11211:11211 -d memcached:1.5.16

三、安装MQ

1、安装Rabbitmq

docker pull rabbitmq:management docker run -d --hostname my-rabbit --name rabbit -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -p 15672:15672 -p 5672:5672 -p 25672:25672  rabbitmq:management

15672:控制台端口号

5672:应用访问端口号

账号和密码为:admin

2、安装Activemq

docker pull  webcenter/activemq docker run -d --name activemq -p 61616:61616 -p 8162:8161 webcenter/activemq

默认的登录密码为admin admin

3、安装kafka

docker pull wurstmeister/zookeeper docker pull wurstmeister/kafka

启动zk

docker run -d --name kafkazookeeper -p 2181:2181 --restart=always -t wurstmeister/zookeeper

启动kafka

docker run -d --name kafka -p 9092:9092 --restart=always -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=192.168.8.6:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.8.6:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -t wurstmeister/kafka

4、安装rocketmq

启动NameServer:

docker run -d -p 9876:9876 --name rmqserver  foxiswho/rocketmq:server-4.5.1

启动broker:

docker run -d -p 10911:10911 -p 10909:10909\ --name rmqbroker --link rmqserver:namesrv\ -e "NAMESRV_ADDR=namesrv:9876" -e "JAVA_OPTS=-Duser.home=/opt"\ -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m"\ foxiswho/rocketmq:broker-4.5.1

Broker容器中默认的配置文件的路径为:

/etc/rocketmq/broker.conf

也可以通过-v参数指定本机的配置文件:

docker run -d -p 10911:10911 -p 10909:10909\ --name rmqbroker --link rmqserver:namesrv\ -e "NAMESRV_ADDR=namesrv:9876" -e "JAVA_OPTS=-Duser.home=/opt"\ -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m"\ -v /conf/broker.conf:/etc/rocketmq/broker.conf \ foxiswho/rocketmq:broker-4.5.1

启动rocketmq console

docker run -d --name rmqconsole -p 8180:8080 --link rmqserver:namesrv\ -e "JAVA_OPTS=-Drocketmq.namesrv.addr=namesrv:9876\ -Dcom.rocketmq.sendMessageWithVIPChannel=false"\ -t styletang/rocketmq-console-ng

四、安装ELK

1、安装elk

[root@ZhiNeng~]# cat /etc/sysctl.conf
vm.max_map_count=262144   #加文末
[root@ZhiNeng~]# sysctl -p   #验证

docker  pull  sebp/elk
docker run -p 5601:5601 -p 9200:9200 -p 5044:5044 -e ES_MIN_MEM=128m -e ES_MAX_MEM=1024m -it --name elk sebp/elk

2、安装Elasticsearch

docker pull elasticsearch:6.5.4
docker create --name elasticsearch --net host -e "discovery.type=single-node" -e "network.host=172.16.55.185" elasticsearch:6.5.4
docker start elasticsearch
docker logs elasticsearch

3、安装elasticsearch-head

docker pull mobz/elasticsearch-head:5
docker create --name elasticsearch-head -p 9100:9100 mobz/elasticsearch-head:5
docker start elasticsearch-head

4、安装solr

docker run --name mysolr -d -p 8983:8983 solr
docker  exec  -it  实例id  /bin/bash
cp -r server/solr/configsets/_default/conf /var/solr/data/collection1

五、安装ZK

docker pull zookeeper:3.5
docker run -itd --name zk -p 2181:2181 zookeeper:3.5

六、安装FastDFS

docker pull morunchang/fastdfs
docker run -d --name tracker --net=host morunchang/fastdfs sh tracker.sh
docker run -d --name storage --net=host -e TRACKER_IP=172.168.20.221:22122 -e GROUP_NAME=group1 morunchang/fastdfs sh storage.sh
# 修改nginx的配置
docker exec -it storage  /bin/bash
vi /data/nginx/conf/nginx.conf
location /group1/M00 {
   proxy_next_upstream http_502 http_504 error timeout invalid_header;
     proxy_cache http-cache;
     proxy_cache_valid  200 304 12h;
     proxy_cache_key $uri$is_args$args;
     proxy_pass http://fdfs_group1;
     expires 30d;
 }

七、安装Nacos

docker run --restart=always --env MODE=standalone --name nacos -d -p 8848:8848 nacos/nacos-server

访问地址:http://localhost:8848/nacos

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

Docker学习笔记 展开 收起
README
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gitfeige/docker.git
git@gitee.com:gitfeige/docker.git
gitfeige
docker
Docker
master

搜索帮助