docker使用阿里云镜像加速
1. 安装/升级Docker客户端
推荐安装1.10.0以上版本的Docker客户端,参考文档 docker-ce
2. 配置镜像加速器
针对Docker客户端版本大于 1.10.0 的用户

您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://p7ldxz2x.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

参考地址:https://www.cnblogs.com/luoocean/p/11608111.html

docker核心概念
docker主机:安装了docker程序的机器
cocker客户端:连接docker主机,操作docker的客户端
docker仓库:用来保存镜像,可以理解为代码仓库
docker镜像:软件打包好的镜像,放在docker仓库中
docker容器:镜像启动后的实例,称为一个容器;容器是一个或者一组应用

docker使用步骤
1.安装docker
2.去docker仓库找到这个软件对应的镜像
3.使用docker运行这个镜像,这个镜像就会生成一个docker容器
4.容器的使用停止,就是停止软件

linux安装docker
1.vmware、virtualbox安装
2.导入虚拟机文件
3.双击linux虚拟机:使用root/123456登录
4.使用客户端连接linux服务器进行命令操作
5.设置虚拟机网络
桥接网络-》选好网卡-》接入网线
6.设置好网络以后,使用命令重启虚拟机的网络
service network restart
7.查看linux的ip地址
ip addr
8.使用客户端连接linux服务器进行命令操作

安装docker
查看系统centos核版本 uname -r(docker要求centos系统的内核版本高于3.10)
升级软件包及内核 yum update
安装docker yum install docker
启动docker systemctl start docker
将docker服务设为开机启动 systemctl enable docker

docker常见操作
容器操作 软件镜像(QQ安装程序)-》运行-》容器

# 查看本地所有镜像docker images
 
#检索镜像 docker search *
[root@VM_0_8_centos ~]# docker search mysql
NAME                              DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mysql                             MySQL is a widely used, open-source relation…   9173                [OK]
mariadb                           MariaDB is a community-developed fork of MyS…   3265                [OK]
mysql/mysql-server                Optimized MySQL Server Docker images. Create…   677                                     [OK]
centos/mysql-57-centos7           MySQL 5.7 SQL database server                   70
mysql/mysql-cluster               Experimental MySQL Cluster Docker images. Cr…   63
centurylink/mysql                 Image containing mysql. Optimized to be link…   61                                      [OK]
deitch/mysql-backup               REPLACED! Please use http://hub.docker.com/r…   41                                      [OK]
bitnami/mysql                     Bitnami MySQL Docker Image                      36                                      [OK]
tutum/mysql                       Base docker image to run a MySQL database se…   34
schickling/mysql-backup-s3        Backup MySQL to S3 (supports periodic backup…   29                                      [OK]
prom/mysqld-exporter                                                              26                                      [OK]
linuxserver/mysql                 A Mysql container, brought to you by LinuxSe…   24
centos/mysql-56-centos7           MySQL 5.6 SQL database server                   19
circleci/mysql                    MySQL is a widely used, open-source relation…   18
mysql/mysql-router                MySQL Router provides transparent routing be…   14
arey/mysql-client                 Run a MySQL client from a docker container      13                                      [OK]
databack/mysql-backup             Back up mysql databases to... anywhere!         10
openshift/mysql-55-centos7        DEPRECATED: A Centos7 based MySQL v5.5 image…   6
fradelg/mysql-cron-backup         MySQL/MariaDB database backup using cron tas…   5                                       [OK]
genschsa/mysql-employees          MySQL Employee Sample Database                  4                                       [OK]
devilbox/mysql                    Retagged MySQL, MariaDB and PerconaDB offici…   2
ansibleplaybookbundle/mysql-apb   An APB which deploys RHSCL MySQL                2                                       [OK]
jelastic/mysql                    An image of the MySQL database server mainta…   1
monasca/mysql-init                A minimal decoupled init container for mysql    0
widdpim/mysql-client              Dockerized MySQL Client (5.7) including Curl…   0                                       [OK]
 
# 安装镜像  docker pull mysql/ docker pull mysql:*(TAG)
[root@VM_0_8_centos ~]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
50e431f79093: Pull complete
dd8c6d374ea5: Pull complete
c85513200d84: Pull complete
55769680e827: Pull complete
e27ce2095ec2: Pull complete
5943eea6cb7c: Pull complete
3ed8ceae72a6: Pull complete
91d1e510d72b: Pull complete
98ce65c663bc: Pull complete
27d4ac9d012a: Pull complete
Digest: sha256:2c90303e910d7d5323935b6dc4f8ba59cc1ec99cf1b71fd6ca5158835cffdc9c
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
 
# 根据镜像启动容器 docker run --name container-name -d image-name:[tag]
1.--name:自定义容器名,不指定时,docker 会自动生成一个名称
2.-d:表示后台运行容器
3.image-name:指定运行的镜像名称以及 Tag
4.-p 表示进行服务器与 Docker 容器的端口映射,默认情况下容器中镜像占用的端口是 Docker 容器中的端口与外界是隔绝的,必须进行端口映射才能访问
[root@VM_0_8_centos ~]# docker run --name mytomcat -d tomcat
d6599b9950a40a01e6baa54824e1ddb8372a0d50dcf250203bbab3b574466907
 
# 查看运行中的容器 docker ps	
[root@VM_0_8_centos ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
791af0394d35        nginx               "nginx -g 'daemon of…"   6 months ago        Up 6 months         0.0.0.0:8081->80/tcp   runoob-nginx-test
 
# 停止运行中镜像 docker stop containerid/names
[root@VM_0_8_centos ~]# docker stop 791af0394d35
791af0394d35
 
# 查看所有的容器 docker ps -a
[root@VM_0_8_centos ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
791af0394d35        nginx               "nginx -g 'daemon of…"   6 months ago        Exited (0) 43 seconds ago                       runoob-nginx-test
20c48763749a        ubuntu              "echo hello docker"      6 months ago        Exited (0) 6 months ago                         magical_benz
0ab1ee80cdbf        ubuntu              "echo hello docker"      6 months ago        Exited (0) 6 months ago                         dazzling_thompson
1715534a866d        ubuntu              "echo hello docker"      6 months ago        Exited (0) 6 months ago                         interesting_tharp
 
# 删除本地镜像 docker rmi IMAGE-ID
[root@VM_0_8_centos ~]# docker rmi 4e7840b49fad
Untagged: tomcat:latest
 
#删除容器 docker container rm  container-ID
[root@VM_0_8_centos ~]# docker container rm  d6599b9950a4
d6599b9950a4
 
#查看容器的实时日志
docker logs -f -t -n=5 2999b546a33a
 
# -p:将主机的端口映射到容器的一个端口 主机端口:容器内部的端口
[root@VM_0_8_centos ~]# docker run --name mytomcat -d -p 8877:8877 tomcat
c6153a092d99edb1ea86592cd35492bdd6fb5a6ddb1d27d5a73a7c3bc35c7a70

docker安装mysql

# 拉取mysql镜像
[root@VM_0_8_centos ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
6d28e14ab8c8: Pull complete
dda15103a86a: Pull complete
55971d75ab8c: Pull complete
f1d4ea32020b: Pull complete
61420072af91: Pull complete
05c10e6ccca5: Pull complete
7e0306b13322: Pull complete
b2e2caa5b6cf: Pull complete
38d3c3421b5f: Pull complete
77ca269db077: Pull complete
4b9f3d38986a: Pull complete
Digest: sha256:77f6e10afdf66b58c677af6ac756279826f3c32c30e1a7e642e971fbbc11a061
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
 
# 安装镜像
[root@VM_0_8_centos ~]# docker run --name mysql01 -e MYSQL_ROOT_PASSWORD=123456  -d -p 3307:3306 mysql:5.7
3508dcd658432746d822a57d246e1ce00a053a2239123e6edd52d5410c53406d
 
# 指定mysql配置的一些参数
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
 
# 挂载配置文件夹,将本机的/my/custom挂载到容器some-mysql的/etc/mysql/conf.d下
docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag

redis容器挂载外部配置文件

# docker run -p 6380:6379 --name myredis -v /docker/myredis/conf/redis.conf:/usr/local/etc/redis/redis.conf  -d redis:4 redis-server /usr/local/etc/redis/redis.conf
 
-v -v /docker/myredis/conf/redis.conf:/usr/local/etc/redis/redis.conf是本地有一个/docker/myredis/conf/目录,里边有一个redis.conf配置文件(一定要对应镜像redis版本),这样修改本地配置文件,就等于修改容器的配置了。

发表评论

邮箱地址不会被公开。 必填项已用*标注