ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

docker使用

2022-02-21 17:31:52  阅读:142  来源: 互联网

标签:容器 systemd id 使用 镜像 docker Docker


Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源。
基本概念:
镜像(Image):相当于是一个系统。比如官方镜像 ubuntu:16.04 就包含了完整的一套 Ubuntu16.04 最小系统。

容器(Container):镜像是静态的定义,容器是镜像运行时的实体。容器可以被创建、启动、停止、删除、暂停等。

仓库(Repository):仓库可看成一个控制中心,用来保存镜像。

命令:

离线安装docker
卸载旧版本
yum remove docker  docker-common docker-selinux docker-engine
wget https://download.docker.com/linux/static/stable/x86_64/docker-19.03.9.tgz
将解压出来的docker文件内容移动到 /usr/bin/ 目录下
将docker注册为service
vi /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
启动
chmod +x /etc/systemd/system/docker.service #添加文件权限并启动docker
systemctl daemon-reload #重载unit配置文件
systemctl start docker #启动Docker
systemctl enable docker.service #设置开机自启

Docker 镜像加速
请在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件):
{"registry-mirrors":["https://reg-mirror.qiniu.com/"]}

查看Docker状态
systemctl status docker
查看Docker版本
docker info
查看docker 镜像
docker image ls
查看docker 容器
docker ps -a
停止容器
docker stop id
删除容器
docker rm id
使用镜像启动一个容器,参数为以命令行模式进入该容器:
$ docker run -it ubuntu /bin/bash 
-itd d表示后台运行
-p 5000:5000 容器内部的 5000 端口映射到我们本地主机的 5000 端口上
启动一个已停止的容器
docker start
进入容器
docker exec -it id /bin/bash
查看容器内部的标准输出
docker logs -f id
查看容器内部运行的进程
docker top id
返回一个 JSON 文件记录着 Docker 容器的配置和状态信息
docker inspect wizardly_chandrasekhar

拉取镜像
默认从Docker Hub 获取
docker image pull rancher/rke-tools:v0.1.52
保存镜像
docker save 镜像id > /home/mysql.tar
载入镜像
docker load -i mysql.tar

标签:容器,systemd,id,使用,镜像,docker,Docker
来源: https://blog.csdn.net/wste3567/article/details/123008931

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有