Ubuntu离线安装docker以及docker-compose

一、基础组件

docker链接: https://pan.baidu.com/s/1A5xVkus8ZNT5hXfVZ5yCcQ 提取码: rk7b

docker-compose链接: https://pan.baidu.com/s/1fdqk-CmEp4twA0vvlSjF7A 提取码: ruk9

二、docker安装

# 创建基础路径 将docker-18.06.1-ce.tgz文件放置到此目录下
mkdir ~/docker
cd ~/docker

# 解压docker文件
tar -xvf docker-18.06.1-ce.tgz

# 将解压出来的docker目录下的文件移动到/usr/bin/目录下
cp ~/docker/* /usr/bin/

# 编写docker服务文件docker.service,将docker注册为系统service服务
vim /etc/systemd/system/docker.service

# 添加docker文件权限并启动docker
chmod +x /etc/systemd/system/docker.service

systemctl daemon-reload
systemctl start docker          #启动Docker
systemctl enable docker.service #设置开机自启

# 验证docker是否安装成功
systemctl status docker #查看Docker状态
docker -v               #查看Docker版本
#docker.service文件
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
 
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
 
[Install]
WantedBy=multi-user.target

三、docker-compose安装

# 将docker-compose-Linux-x86_64文件放置到此目录下
cd ~/docker

# 将docker-compose-Linux-x86_64文件拷贝到/usr/bin目录或/usr/local/bin目录
sudo cp docker-compose-Linux-x86_64 /usr/local/bin/docker-compose

# 赋予docker-compose文件权限
sudo chmod +x /usr/local/bin/docker-compose

# 验证是否安装成功
sudo docker-compose -v

四、常用docker-compose指令

# 查看当前启动的容器
sudo docker-compose ps

# 启动部分服务在后边加服务名,不加表示启动所有,-d 表示在后台运行
sudo docker-compose up [nginx|php| ...] -d

# 停止和启动类似
sudo docker-compose stop [nginx|php| ...]

# 停止并删除相关的容器
sudo docker-compose down [nginx|php| ...]

# 删除所有未运行的容器
sudo docker rm $(sudo docker ps -a -q)

# 删除所有未运行的镜像,-f 可以强制删除
sudo docker rmi $(sudu docker images -q)

# 重新构建过清理无效数据(注意如果执行 docker images -a 会出现一些 none 的镜像,这些是构建镜像的中间层不占用空间也不是垃圾数据,不用管,使用下面的命令就是清理无效数据)
sudo docker system prune

 

你可能感兴趣的:(安装部署)