docker(docker)

Linux配置网络vi /etc/sysconfig/network-scripts/ifcfg-ens33 (33)

ststemctl restart network

安装docker步骤:1.安装yum-utilyum install -y yum-utils2.设置yum源yum-config-manager –add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo3.安装docker引擎yum install docker-ce docker-ce-cli containerd.io

4.启动dockersystemctl start docker –启动systemctl stop docker –停止systemctl restart docker –重启systemctl status docker –查看状态systemctl enable docker –设置开启启动

5.设置镜像加速vi /etc/docker/daemon.json{ “registry-mirrors”: [“http://hub-mirror.c.163.com”, “https://docker.mirrors.ustc.edu.cn”]}

# 重新加载某个服务的配置文件sudo systemctl daemon-reload# 重新启动 dockersudo systemctl restart docker

#镜像命令docker images –查看镜像docker search –搜索镜像docker pull –拉取镜像docker system df — 查看镜像/容器/数据卷所占的空间docker rmi -f –删除镜像docker rmi -f $(docker ps -qa) –删除全部镜像

仓库名和标签都为none的镜像叫虚悬镜像

#容器命令docker run [OPTIONS] IMAGE [COMMAND] [ARG…] –新建/启动容器例如: docker run -it –name=”redis” redis:6.0.8 /bin/bash–name=”容器新名字” 为容器指定一个名称;-d: 后台运行容器并返回容器ID,也即启动守护式容器(后台运行);

-i:以交互模式运行容器,通常与 -t 同时使用;-t:为容器重新分配一个伪输入终端,通常与 -i 同时使用;也即启动交互式容器(前台有伪终端,等待交互); -P: 随机端口映射,大写P-p: 指定端口映射,小写p

docker ps [OPTIONS] –查看当前所有运行的容器-a :列出当前所有正在运行的容器+历史上运行过的-l :显示最近创建的容器。-n:显示最近n个创建的容器。-q :静默模式,只显示容器编号

exit –退出容器 (run进去容器,exit退出,容器停止)Ctrl+p+q –退出容器 (run进去容器,ctrl+p+q退出,容器不停止)

docker start 容器ID或者容器名 –启动已停止运行的容器docker restart 容器ID或者容器名 –重启docker stop 容器ID或者容器名 –停止docker kill 容器ID或者容器名 –强制停止docker rm 容器ID或者容器名 –删除docker rm -f $(docker ps -a -q) — 一次性删除多个docker logs 容器ID –查看容器日志docker top 容器ID –查看容器内容运行进程docker inspect redis(容器名称) –查询容器详细信息

#进入正在运行的容器并以命令行交互docker exec -it 容器ID /bin/bash (推荐使用)exec 是在容器中打开新的终端,并且可以启动新的进程用exit退出,不会导致容器的停止。

docker attach 容器ID 直接进入容器启动命令的终端,不会启动新的进程 用exit退出,会导致容器的停止。

#把容器文件拷贝到主机docker cp 容器ID:容器内路径 目的主机路径例如: docker cp 9430f384f131:/root/aa.txt /root

#导出整个容器docker export 容器ID > 文件名.tar.gz

#导入整个容器cat 文件名.tar.gz | docker import – 镜像用户(finnlee)/镜像名(centos):镜像版本号[6.0.8]

#Docker镜像commit操作(使一个容器副本成为一个新的镜像)docker commit -m=”提交的描述信息” -a=”作者” 容器ID 要创建的目标镜像名:[标签名]

//修改配置内容mounts//进入容器目录docker exec -it nginx07 /bin/bash

//dockerfile

————————

Linux配置网络vi /etc/sysconfig/network-scripts/ifcfg-ens33 (33)

ststemctl restart network

安装docker步骤:1.安装yum-utilyum install -y yum-utils2.设置yum源yum-config-manager –add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo3.安装docker引擎yum install docker-ce docker-ce-cli containerd.io

4.启动dockersystemctl start docker –启动systemctl stop docker –停止systemctl restart docker –重启systemctl status docker –查看状态systemctl enable docker –设置开启启动

5.设置镜像加速vi /etc/docker/daemon.json{ “registry-mirrors”: [“http://hub-mirror.c.163.com”, “https://docker.mirrors.ustc.edu.cn”]}

# 重新加载某个服务的配置文件sudo systemctl daemon-reload# 重新启动 dockersudo systemctl restart docker

< strong > # image command < / strong > docker images — view image docker search — search image docker pull — pull image docker system DF — view the space occupied by image / container / data volume docker RMI – F — delete image docker RMI – f $(docker PS – QA) — delete all images

The image whose warehouse name and label are none is called suspended image

< strong > # container command < / strong > docker run [options] image [command] [Arg…]– Create / start a container, for example: docker run – it — name = “redis” redis: 6.0.8 / bin / bash — name = “container new name” specify a name for the container- d: Run the container in the background and return the container ID, that is, start the guardian container (running in the background);

-i: Run the container in interactive mode, usually at the same time as – t- t: Reassign a pseudo input terminal to the container, which is usually used together with – I; That is, start the interactive container (there is a pseudo terminal at the foreground, waiting for interaction)- P: Random port mapping, uppercase P-P: specify port mapping, lowercase p

Docker PS [options] – view all currently running containers – A: list all currently running containers + historically running containers – L: display recently created containers- n: Displays the last n containers created- Q: silent mode, only the container number is displayed

Exit — exit the container (run into the container, exit, container stop) Ctrl + P + Q — exit the container (run into the container, Ctrl + P + Q exit, container does not stop)

Docker start container ID or container name — start a stopped container docker restart container ID or container name — restart docker stop container ID or container name — stop docker kill container ID or container name — force docker RM to stop container ID or container name — delete docker RM – f $(docker PS – A – Q) –Delete multiple docker logs at one time container ID — View container log docker top container ID — View container content run process docker inspect redis (container name) — Query container details

< strong > # enter the running container and interact with the command line < / strong > docker exec – it container ID / bin / bash (recommended) exec opens a new terminal in the container and can start a new process. Exit with exit will not stop the container.

The docker attach container ID directly enters the terminal of the container start command. It will not start a new process and exit with exit, which will lead to the stop of the container.

< strong > # copy the container file to the host < / strong > docker CP container ID: path in the container destination host path, for example: docker CP 9430f384f131: / root / AA txt /root

< strong > # export entire container < / strong > docker export container ID & gt; File name tar. gz

< strong > # import the whole container < / strong > cat file name tar. GZ | docker import – image user (finnlee) / image name (CentOS): image version number [6.0.8]

#Docker image commit operation (make a container copy a new image) docker commit – M = “description of submitted” – a = “author” container ID target image name to be created: [tag name]

//Modify the configuration contents mounts / / enter the container directory docker exec – it nginx07 / bin / Bash

//dockerfile