Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源。
1、方便项目交付与部署及扩容
2、更高的资源利用率,节省开支
3、方便隔离应用,服务器整合等等。。。
1、web应用的自动化打包和发布
2、自动化测试和持续集成、发布
3、在服务型环境中部署和调整数据库或其他的后台应用
4、从头编译或者扩展现有的OpenShift或Cloud Foundry平台来搭建自己的PaaS环境
docker支持windows、linux、macos等系统下安装,同时docker分为社区版CE和企业版EE
1)下载安装包
xxxxxxxxxx
11$ wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz
2)解压
xxxxxxxxxx
11$ tar -zxvf docker-18.06.3-ce.tgz
3)复制到 /usr/bin/ 目录下
xxxxxxxxxx
11$ cp docker/* /usr/bin/
4)在/etc/systemd/system/目录下新增docker.service文件
xxxxxxxxxx
21$ cd /etc/systemd/system/
2$ vim docker.service
xxxxxxxxxx
331[Unit]
2Description=Docker Application Container Engine
3Documentation=https://docs.docker.com
4After=network-online.target firewalld.service
5Wants=network-online.target
6
7[Service]
8Type=notify
9# the default is not to use systemd for cgroups because the delegate issues still
10# exists and systemd currently does not support the cgroup feature set required
11# for containers run by docker
12ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.1
13ExecReload=/bin/kill -s HUP $MAINPID
14# Having non-zero Limit*s causes performance problems due to accounting overhead
15# in the kernel. We recommend using cgroups to do container-local accounting.
16LimitNOFILE=infinity
17LimitNPROC=infinity
18LimitCORE=infinity
19# Uncomment TasksMax if your systemd version supports it.
20# Only systemd 226 and above support this version.
21#TasksMax=infinity
22TimeoutStartSec=0
23# set delegate yes so that systemd does not reset the cgroups of docker containers
24Delegate=yes
25# kill only the docker process, not all processes in the cgroup
26KillMode=process
27# restart the docker process if it exits prematurely
28Restart=on-failure
29StartLimitBurst=3
30StartLimitInterval=60s
31
32[Install]
33WantedBy=multi-user.target
5)重新加载配置文件
xxxxxxxxxx
11$ systemctl daemon-reload
6)给docker.service文件添加执行权限
xxxxxxxxxx
11$ chmod +x /etc/systemd/system/docker.service
7)启动docker
xxxxxxxxxx
11$ systemctl start docker
8)查看docker服务状态
xxxxxxxxxx
11$ systemctl status docker
1)查看是否已安装docker列表
xxxxxxxxxx
11$ yum list installed | grep docker
2)安装docker
xxxxxxxxxx
11$ yum -y install docker
3)启动docker
xxxxxxxxxx
11$ systemctl start docker
4)查看docker服务状态
xxxxxxxxxx
11$ systemctl status docker
1)获取shell脚本
xxxxxxxxxx
11$ curl -fsSL https://get.docker.com -o get-docker.sh
2)执行安装
xxxxxxxxxx
11$ DRY_RUN=1 sh ./get-docker.sh
xxxxxxxxxx
11$ brew install docker
到docker官网(https://docs.docker.com/desktop/mac/install/)下载对应的 xxx.dmg文件,双击dmg文件,然后拖动安装
1)到docker官网(https://docs.docker.com/desktop/windows/install/)下载对应的 .exe 文件。
2)和普通软件一样的安装方式,一直点击下一步,最后完成。
1、查看docker信息
xxxxxxxxxx
11$ docker info
2、拉取镜像
xxxxxxxxxx
11$ docker pull centos
3、运行容器
xxxxxxxxxx
11$ docker run -itd --name centos-7 centos
4、进入容器
xxxxxxxxxx
11$ docker exec -it centos-7 /bin/bash
如果要以root身份进入:docker exec -it -u root centos-7 /bin/bash
5、开启/关闭/重启容器
xxxxxxxxxx
51$ docker start centos-7
2
3$ docker stop centos-7
4
5$ docker restart centos-7
6、删除镜像
xxxxxxxxxx
11$ docker rmi centos
7、启动所有的容器
xxxxxxxxxx
11$ docker start $(docker ps -a | awk '{ print $1}' | tail -n +2)
8、关闭所有的容器
xxxxxxxxxx
11$ docker stop $(docker ps -a | awk '{ print $1}' | tail -n +2)
9、删除所有的容器
xxxxxxxxxx
11$ docker rm $(docker ps -a | awk '{ print $1}' | tail -n +2)
10、删除所有的镜像
xxxxxxxxxx
11$ docker rmi $(docker images | awk '{print $3}' |tail -n +2)
ps:tail -n +2 表示从第二行开始读取
11、更多命令请使用docker help
来查看
Transaction Check Error: file /usr/bin/docker from install of docker-io-1.7.1-2.el6.x86_64 conflicts with file from package docker-1.5-5.el6.x86_64
这个是因为先装了docker,再装docker-io后的结果,
解决方法是sudo yum remove docker
后再sudo yum install docker-io docker-io-devel
即可