安装
版本:docker(19.03.9)docker-compose(2.14.0)
1. 离线安装
1.1 下载安装docker tar包
可直接使用地址在浏览器下载 ,再导入
curl -O -J -L https://download.docker.com/linux/static/stable/x86_64/docker-19.03.9.tgz
1.2 解压tar包
tar -xvf docker-19.03.9.tgz
1.3 将解压后的文件中的可执行文件移动到/usr/bin下
cp docker/* /usr/bin/
1.4 配置启动文件
[root@iZbp13sno1lc2yxlhjc4b3Z ~]#vim /etc/systemd/system/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
1.5 启动服务
systemctl daemon-reload
systemctl start docker
systemctl enable docker.service
2. 在线安装
yun install -y docker
3. 安装docker-compose
3.1 下载
https://github.com/docker/compose/releases
3.2 配置
sudo mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose -v
操作
4. 测试
编写一个简单的docker-compose
# 1. 编辑
# vi docker-compose.yaml
version: '3'
services:
mysql:
container_name: mysql_test
image: mysql:5.7
ports:
- "3306:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: 123456
networks:
net1:
ipv4_address: 172.21.0.2
networks:
net1:
ipam:
config:
- subnet: 172.21.0.0/24
# 2. 运行:docker-compose up -d
# 3. 查看端口:ss -ntlp | grep 3306