Docker持续体验

upload successful

Docker持续体验


第一次听说到Docker是在2016年的时候,最近因为百度云服务器到期,要将一些服务迁移到阿里云上,在安装一些中间件的时候,才体会到了Docker的强大。


安装Docker

主要记录在Linux上安装,Windows可以直接下载.msi安装程序安装。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

检查Linux内核版本,Docker要求Linux内核版本高于3.10
uname -r

更新系统yum源
yum update
... // 省略更新代码

卸载旧版本,如果有安装Docker
sudo yum remove docker docker-common docker-selinux docker-engine

安装需要的安装包
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

设置Docker的yum源
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

查看所有Docker仓库中的版本,选定版本进行安装
yum list docker-ce --showduplicates | sort -r

安装Docker
sudo yum install docker-ce-19.03.5 docker-ce-cli-19.03.5 containerd.io

Docker镜像拉取

镜像拉取命令十分简单,只需要执行如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

docker search nginx

NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 12821 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1752 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 759 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 96
bitnami/nginx Bitnami nginx Docker Image 78 [OK]
tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 64 [OK]
jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 46
nginxdemos/hello NGINX webserver that serves a simple page co… 42 [OK]
nginx/unit NGINX Unit is a dynamic web and application … 36
jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 35 [OK]
nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 28
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 22 [OK]
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 18 [OK]
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 13
blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 13 [OK]
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 12
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 12
raulr/nginx-wordpress Nginx front-end for the official wordpress:f… 12 [OK]
nginx/nginx-prometheus-exporter NGINX Prometheus Exporter 9
sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… 7 [OK]
mailu/nginx Mailu nginx frontend 6 [OK]
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 4 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 1 [OK]
wodby/nginx Generic nginx 0 [OK]
centos/nginx-110-centos7 Platform for running nginx 1.10 or building … 0

选择需要拉取的镜像执行

1
docker pull nginx:latest

Docker容器启动

以启动Mysql镜像为例:

1
2
3
4
5
6
7
8
docker run -p 本机映射端口:镜像映射端口 -d  --name 启动镜像名称 -e 镜像启动参数  镜像名称:镜像版本号

-p 本机端口和容器启动端口映射
-d 后台运行
--name 容器名称
-e 镜像启动参数

docker run -p 3306:3306 -d --name mysql01 -e MYSQL_ROOT_PASSWORD=admin mysql:5.6

Docker可视化管理工具

可以参考Portainer工具