Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源。
1、方便项目交付与部署及扩容
2、更高的资源利用率,节省开支
3、方便隔离应用,服务器整合等等。。。
1、web应用的自动化打包和发布
2、自动化测试和持续集成、发布
3、在服务型环境中部署和调整数据库或其他的后台应用
4、从头编译或者扩展现有的OpenShift或Cloud Foundry平台来搭建自己的PaaS环境
docker支持windows、linux、macos等系统下安装,同时docker分为社区版CE和企业版EE
1)下载安装包
xxxxxxxxxx11$ wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz2)解压
xxxxxxxxxx11$ tar -zxvf docker-18.06.3-ce.tgz3)复制到 /usr/bin/ 目录下
xxxxxxxxxx11$ cp docker/* /usr/bin/4)在/etc/systemd/system/目录下新增docker.service文件
xxxxxxxxxx21$ cd /etc/systemd/system/2$ vim docker.servicexxxxxxxxxx331[Unit]2Description=Docker Application Container Engine3Documentation=https://docs.docker.com4After=network-online.target firewalld.service5Wants=network-online.target6 7[Service]8Type=notify9# the default is not to use systemd for cgroups because the delegate issues still10# exists and systemd currently does not support the cgroup feature set required11# for containers run by docker12ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.113ExecReload=/bin/kill -s HUP $MAINPID14# Having non-zero Limit*s causes performance problems due to accounting overhead15# in the kernel. We recommend using cgroups to do container-local accounting.16LimitNOFILE=infinity17LimitNPROC=infinity18LimitCORE=infinity19# Uncomment TasksMax if your systemd version supports it.20# Only systemd 226 and above support this version.21#TasksMax=infinity22TimeoutStartSec=023# set delegate yes so that systemd does not reset the cgroups of docker containers24Delegate=yes25# kill only the docker process, not all processes in the cgroup26KillMode=process27# restart the docker process if it exits prematurely28Restart=on-failure29StartLimitBurst=330StartLimitInterval=60s31 32[Install]33WantedBy=multi-user.target5)重新加载配置文件
xxxxxxxxxx11$ systemctl daemon-reload 6)给docker.service文件添加执行权限
xxxxxxxxxx11$ chmod +x /etc/systemd/system/docker.service7)启动docker
xxxxxxxxxx11$ systemctl start docker8)查看docker服务状态
xxxxxxxxxx11$ systemctl status docker1)查看是否已安装docker列表
xxxxxxxxxx11$ yum list installed | grep docker2)安装docker
xxxxxxxxxx11$ yum -y install docker3)启动docker
xxxxxxxxxx11$ systemctl start docker4)查看docker服务状态
xxxxxxxxxx11$ systemctl status docker1)获取shell脚本
xxxxxxxxxx11$ curl -fsSL https://get.docker.com -o get-docker.sh2)执行安装
xxxxxxxxxx11$ DRY_RUN=1 sh ./get-docker.shxxxxxxxxxx11$ 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信息
xxxxxxxxxx11$ docker info2、拉取镜像
xxxxxxxxxx11$ docker pull centos3、运行容器
xxxxxxxxxx11$ docker run -itd --name centos-7 centos4、进入容器
xxxxxxxxxx11$ docker exec -it centos-7 /bin/bash如果要以root身份进入:docker exec -it -u root centos-7 /bin/bash
5、开启/关闭/重启容器
xxxxxxxxxx51$ docker start centos-72
3$ docker stop centos-74
5$ docker restart centos-76、删除镜像
xxxxxxxxxx11$ docker rmi centos7、启动所有的容器
xxxxxxxxxx11$ docker start $(docker ps -a | awk '{ print $1}' | tail -n +2)8、关闭所有的容器
xxxxxxxxxx11$ docker stop $(docker ps -a | awk '{ print $1}' | tail -n +2)9、删除所有的容器
xxxxxxxxxx11$ docker rm $(docker ps -a | awk '{ print $1}' | tail -n +2)10、删除所有的镜像
xxxxxxxxxx11$ 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即可