一、安装docker
- 下载安装包
wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz
- 解压缩
tar -zxvf docker-18.06.3-ce.tgz
- 将可执行文件放到/user/bin/目录下
cp docker/* /usr/bin/
- 在/etc/systemd/system/目录下新增docker.service文件
cat /etc/systemd/system/docker.service
- 写入并按Ctrl+d保存并退出
[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 --selinux-enabled=false --insecure-registry=127.0.0.1
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
6. 给docker.service文件添加执行权限
chmod +x /etc/systemd/system/docker.service
- 重新加载配置文件
systemctl daemon-reload
- 启动
systemctl start docker
设置开机启动
systemctl enable docker.service
每次有修改docker.service文件时都要重新加载下
查看docker服务状态
systemctl status docker
查看docker是否安装成功
docker
安装成功!
二、玩转镜像(虚拟服务)
- 查看现在运行的容器
docker container ls
- 关闭指定容器
docker stop ny
- 查看镜像列表
docker image ls
- 保存到镜像
docker commit -m "临时保存" ny zml_ny
- 删除容器
docker rm ny
- 开启容器
docker run -d --name ny --privileged=true -p 8081:8081 -p 8082:8082 -p 8083:8083 -p 8084:8084 -p 5003:22 -p 3307:3306 -p 8085:8085 zml_ny /usr/sbin/init -c "systemctl start mysqld.service"
- 进去指定容器
docker exec -it ny /bin/bash
- 启动容器
docker start ny