首页 > 其他分享 >安装docker容器

安装docker容器

时间:2023-08-10 18:13:45浏览次数:40  
标签:bin 容器 systemd compose service usr docker 安装

写在前面

之前写过一篇关于docker安装的博客,那种方式安装有很多缺点。运行docker和使用docker的时候会产生多个进程,占用Linux主机的资源。于是,我找到了新的方式安装docker。

重要的三个文件

/usr/lib/systemd/system/docker.service

/usr/lib/systemd/system/docker.socket

/usr/lib/systemd/system/containerd.service

开始安装docker

添加docker用户

groupadd docker

下载docker

https://download.docker.com/linux/static/stable/x86_64/docker-20.10.7.tgz

解压

tar xzvf docker-20.10.7.tgz

复制文件到/usr/bin/ 目录下

cp docker/* /usr/bin/

建议把docker文件复制到/usr/bin/目录下,如果移动到别的目录有点问题,systemctl脚本启动不起来。

创建docker.socket文件

cat > /usr/lib/systemd/system/docker.socket << 'EOF'
[Unit]
Description=Docker Socket for the API

[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target
EOF

创建containerd.service文件

cat > /usr/lib/systemd/system/containerd.service << 'EOF'
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd

Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=1048576
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target
EOF

创建docker.server文件

tee /usr/lib/systemd/system/docker.service <<-'EOF'
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service

[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 --graph=/data/docker -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# 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

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# 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
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target
EOF

启动重要的参数:/usr/bin/dockerd --graph=/data/docker -H fd:// --containerd=/run/containerd/containerd.sock

启动docker容器

#重新加载配置文件
systemctl daemon-reload 

#启动
systemctl start docker

#设置开机启动
systemctl enable docker.service

#查看docker服务状态
systemctl status docker

#查看docker版本
docker -v

#查看docker容器里的镜像
docker images

#查看容器数据文件存储路径
docker info |grep "Docker Root"

镜像导入

[root@ncayu docker-images]# docker load -i minio-latest.tar
[root@ncayu docker-images]# docker load -i mysql-5.7.tar
[root@ncayu docker-images]# docker load -i redis-6.2.3.tar

docker进程展示

安装docker-compose1.25.0

curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 添加可执行权限
sudo chmod +x /usr/local/bin/docker-compose
# 添加快捷启动连接
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
# 测试安装结果
docker-compose --version

标签:bin,容器,systemd,compose,service,usr,docker,安装
From: https://www.cnblogs.com/ncayu2025/p/17621147.html

相关文章

  • docker容器的使用
    删除docker容器dockerrmmysql批量删除已经停止的容器#方法一#显示所有的容器,过滤出Exited状态的容器,取出这些容器的ID,sudodockerps-a|grepExited|awk'{print$1}'#查询所有的容器,过滤出Exited状态的容器,列出容器ID,删除这些容器sudodockerrm`dockerps-a|g......
  • docker overlay2是什么
    dockeroverlay2是Docker中的存储驱动之一,用于管理镜像和容器层的数据。它使用最小存储空间来存储像层这样的临时数据。overlay2本质上是多层存储驱动。它将镜像和容器层都视为独立的匿名临时文件系统。然后通过联合挂载将这些层组合成所需的最终文件系统。overlay2使用两个目......
  • docker 删除已停止的容器
    docker删除已停止的容器根据容器的状态,删除Exited状态的容器#根据容器的状态,删除Exited状态的容器sudodockerrm$(sudodockerps-qfstatus=exited)删除所有未运行的容器(已经运行的删除不了,未运行的就一起被删除了)sudodockerrm$(sudodockerps-a-q)查询所有......
  • docker-compose 安装MySQL(单实例)
    需求场景:在开发和测试环境中,或者研究型的环境,对于数据库的安全和稳定性可以稍低一些,那么我们可以通过docker快速部署MySQL服务,降低部署的时间成本。 vimdocker-compose.ymlversion:'3'services:mysql:restart:alwaysprivileged:trueimage:mysql:8.0......
  • docker日志存储限制
    新建/etc/docker/daemon.json,若有就不用新建了。添加log-dirver和log-opts参数,样例如下:#vim/etc/docker/daemon.json{"data-root":"/opt/docker","insecure-registries":["http://10.168.1.130:5000"],"log-driver":......
  • 记录一个windows for Docker启动失败
    Hyper-V的目录错误,导致docker启动失败。因为windowsforDocker依赖Hyper-V,如果Hyper-V不能快速创建虚拟机,就会导致Docker初始化失败。 ......
  • Centos安装rocketmq
    一、创建文件夹        进入我们创建好的文件夹中: //创建文件加mkdirrockmq//进入文件夹cdrockmq二、下载安装包         下载自己所需的版本,我这里是rocketmq4.4.0 //下载安装包wgethttps://archive.apache.org/dist/rocketmq/4.4.0/rocke......
  • 1.Elasticsearch集群包安装、二进制安装与Docker安装
    ElasticsearchElasticsearch是一个实时的全文搜索,存储库和分析引擎https://www.elastic.co/cn/what-is/elasticsearchElasticsearch在速度和可扩展性方面都表现出色,而且还能够索引多种类型的内容,可用于多种场景:应用程序搜索网站搜索企业搜索日志处理和分析基础设施指标和......
  • 2.Elasticsearch单节点安装脚本
    #!/bin/bashES_VERSION=7.17.5#ES_VERSION=7.9.3#ES_VERSION=7.6.2UBUNTU_URL="https://mirrors.tuna.tsinghua.edu.cn/elasticstack/7.x/apt/pool/main/e/elasticsearch/elasticsearch-${ES_VERSION}-amd64.deb"RHEL_URL="https://mirrors.tuna.tsingh......
  • 3.Elasticsearch集群安装脚本
    #!/bin/bashES_VERSION=7.17.5#ES_VERSION=7.9.3#ES_VERSION=7.6.2UBUNTU_URL="https://mirrors.tuna.tsinghua.edu.cn/elasticstack/7.x/apt/pool/main/e/elasticsearch/elasticsearch-${ES_VERSION}-amd64.deb"RHEL_URL="https://mirrors.tuna.tsinghu......