当前位置:网站首页>Dockler的基础用法
Dockler的基础用法
2022-07-28 17:28:00 【阿木690】
文章目录
- 一、什么是docker
- 二、OCI&OCF
- 三、docker架构
- 四、docker镜像与镜像仓库
- 五、docker对象
- 六、安装及使用docker
- docker安装
- docker加速
- docker常用操作
- docker version:查看版本
- docker info:查看系统信息
- docker pull:拉取镜像
- docker images:列出系统当前所有镜像
- docker search:在docker hub中查找镜像
- docker image history:查看指定镜像的历史记录
- docker image inspect:查看指定镜像的详细信息
- docker create:创建容器(但是容器不会启动)
- docker rm:删除镜像
- docker ps:列出容器
- docker start:启动容器
- docker attach:进入容器
- docker exec:进入容器
- docker inspect:查看容器的详细信息
- docker logs:查看容器日志信息
- docker stop:停止容器
- docker restart:重启容器
- docker kill:杀死正在运行的容器
- docker run:创建容器并直接启动容器.
- docker rm:删除容器
- docker event state
一、什么是docker
docker中的容器:
- lxc --> libcontainer --> runC

二、OCI&OCF
OCI
开放容器计划
- 由Linux基金会主导于2015年6月创立
- 旨在围绕容器格式和运行时制定一个开放的工业化标准
- 包含两个规格
- 运行时规范(运行时规范)
- 图像规格(图像规格)
OCF
开放容器格式
runC 是一个 CLI 工具,用于根据 OCI 规范生成和运行容器
- 容器作为 runC 的子进程启动,可以嵌入到各种其他系统中,而无需运行守护程序
- runC 建立在 libcontainer 之上,libcontainer 是支持数百万个 Docker 引擎安装的相同容器技术
docker提供了一个专门容纳容器镜像的站点:https://hub.docker.com
三、docker架构

四、docker镜像与镜像仓库
为什么镜像仓库名字是Registry而不是repository?在docker中仓库的名字是以应用的名称取名的。

镜像是静态的,而容器是动态的,容器有其生命周期,镜像与容器的关系类似于程序与进程的关系。镜像类似于文件系统中的程序文件,而容器则类似于将一个程序运行起来的状态,也即进程。所以容器是可以删除的,容器被删除后其镜像是不会被删除的。
五、docker对象
使用 Docker 时,您正在创建和使用映像、容器、网络、卷、插件和其他对象。
镜像
- 镜像是只读模板,其中包含创建docker容器的说明。
- 通常,一个镜像基于另一个镜像,并进行一些额外的自定义。
- 您可以创建自己的镜像,也可以只使用其他人创建并在注册表中发布的镜像。
容器
- conntainer是映像的可运行实例。
- 您可以使用docker API或CLI创建、运行、停止、移动或删除容器。
- 您可以将容器连接到一个或多个网络,将存储连接到容器,甚至可以基于其当前状态创建新映像。
六、安装及使用docker
docker安装
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# curl -o docker-ce.repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
[[email protected] yum.repos.d]# sed -i '[email protected]://[email protected]://mirrors.tuna.tsinghua.edu.cn/[email protected]' docker-ce.repo
[[email protected] yum.repos.d]# yum -y install docker-ce
[[email protected] yum.repos.d]# yum clean all
Failed to set locale, defaulting to C.UTF-8
28 files removed
// 启动服务
[[email protected] ~]# systemctl enable --now docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[[email protected] ~]# ls /etc/docker/
key.json
docker加速
docker-ce的配置文件是/etc/docker/daemon.json,此文件默认不存在,需要我们手动创建并进行配置,而docker的加速就是通过配置此文件来实现的。
docker的加速有多种方式:
- docker cn
- 中国科技大学加速器
- 阿里云加速器(需要通过阿里云开发者平台注册帐号,免费使用个人私有的加速器)



[[email protected] ~]# systemctl enable --now docker //启动docker服务
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
// 添加加速器
cat > /etc/docker/daemon.json <<EOF { "registry-mirrors": ["https://kgdsiwq8.mirror.aliyuncs.com"] } EOF
// 重启
[[email protected] ~]# systemctl dameon-reload docker
[[email protected] ~]# systemctl restart docker
docker常用操作
| 命令 | 功能 |
|---|---|
| docker search | Search the Docker Hub for images |
| docker pull | Pull an image or a repository from a registry |
| docker images | List images |
| docker create | Create a new conntainer |
| docker start | Start one or more stopped containers |
| docker run | Run a command in a new container |
| docker attach | Attach to a runninng container |
| docker ps | List containers |
| docker logs | Fetch the logs of a container |
| docker restart | Restart a container |
| docker stop | Stop one or more running containers |
| docker kill | Kill one or more running containers |
| docker rm | Remove onne or more containers |
| docker exec | Run a command in a running container |
| docker info | Display system-wide information |
| docker inspect | Return low-level information on Docker objects |
docker version:查看版本
[[email protected] ~]# docker version
Client: Docker Engine - Community
Version: 20.10.11
API version: 1.41
Go version: go1.16.9
Git commit: dea9396
Built: Thu Nov 18 00:36:58 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.11
API version: 1.41 (minimum version 1.12)
Go version: go1.16.9
Git commit: 847da18
Built: Thu Nov 18 00:35:20 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0
docker info:查看系统信息
[[email protected] ~]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.6.3-docker)
scan: Docker Scan (Docker Inc., v0.9.0)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 1
Server Version: 20.10.11
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc version: v1.0.2-0-g52b36a2
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 4.18.0-257.el8.x86_64
Operating System: CentOS Stream 8
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 3.622GiB
Name: localhost.localdomain
ID: FT3B:RKJB:SBUC:OAL7:NW2C:QBTY:6VIW:PWHU:CWBD:PQPU:D424:BZJU
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
docker pull:拉取镜像
[[email protected] ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
eff15d958d66: Pull complete
1e5351450a59: Pull complete
2df63e6ce2be: Pull complete
9171c7ae368c: Pull complete
020f975acd28: Pull complete
266f639b35ad: Pull complete
Digest: sha256:097c3a0913d7e3a5b01b6c685a60c03632fc7a2b50bc8e35bcaa3691d788226e
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
docker images:列出系统当前所有镜像
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ea335eea17ab 13 days ago 141MB
docker search:在docker hub中查找镜像
[[email protected] ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 15893 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 2098 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 819 [OK]
jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 285
linuxserver/nginx An Nginx container, brought to you by LinuxS… 160
tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 146 [OK]
jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 144 [OK]
alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 110 [OK]
jasonrivers/nginx-rtmp Docker images to host RTMP streams using NGI… 95 [OK]
nginxdemos/hello NGINX webserver that serves a simple page co… 79 [OK]
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 60 [OK]
nginx/nginx-ingress NGINX and NGINX Plus Ingress Controllers fo… 57
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 54
nginxproxy/nginx-proxy Automated Nginx reverse proxy for docker con… 28
staticfloat/nginx-certbot Opinionated setup for automatic TLS certs lo… 25 [OK]
nginx/nginx-prometheus-exporter NGINX Prometheus Exporter for NGINX and NGIN… 22
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 19 [OK]
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 16
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 13
bitwarden/nginx The Bitwarden nginx web server acting as a r… 11
mailu/nginx Mailu nginx frontend 9 [OK]
sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… 7 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 3 [OK]
wodby/nginx Generic nginx 1 [OK]
arnau/nginx-gate Docker image with Nginx with Lua enabled on … 1 [OK]
docker image history:查看指定镜像的历史记录
[[email protected] ~]# docker image history nginx
IMAGE CREATED CREATED BY SIZE COMMENT
ea335eea17ab 13 days ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B
<missing> 13 days ago /bin/sh -c #(nop) STOPSIGNAL SIGQUIT 0B
<missing> 13 days ago /bin/sh -c #(nop) EXPOSE 80 0B
<missing> 13 days ago /bin/sh -c #(nop) ENTRYPOINT ["/docker-entr… 0B
<missing> 13 days ago /bin/sh -c #(nop) COPY file:09a214a3e07c919a… 4.61kB
<missing> 13 days ago /bin/sh -c #(nop) COPY file:0fd5fca330dcd6a7… 1.04kB
<missing> 13 days ago /bin/sh -c #(nop) COPY file:0b866ff3fc1ef5b0… 1.96kB
<missing> 13 days ago /bin/sh -c #(nop) COPY file:65504f71f5855ca0… 1.2kB
<missing> 13 days ago /bin/sh -c set -x && addgroup --system -… 61.1MB
<missing> 13 days ago /bin/sh -c #(nop) ENV PKG_RELEASE=1~bullseye 0B
<missing> 13 days ago /bin/sh -c #(nop) ENV NJS_VERSION=0.7.0 0B
<missing> 13 days ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.21.4 0B
<missing> 13 days ago /bin/sh -c #(nop) LABEL maintainer=NGINX Do… 0B
<missing> 2 weeks ago /bin/sh -c #(nop) CMD ["bash"] 0B
<missing> 2 weeks ago /bin/sh -c #(nop) ADD file:a2405ebb9892d98be… 80.4MB
docker image inspect:查看指定镜像的详细信息
[[email protected] ~]# docker inspect nginx
[
{
"Id": "sha256:ea335eea17ab984571cd4a3bcf90a0413773b559c75ef4cda07d0ce952b00291",
"RepoTags": [
"nginx:latest"
],
"RepoDigests": [
"[email protected]:097c3a0913d7e3a5b01b6c685a60c03632fc7a2b50bc8e35bcaa3691d788226e"
],
"Parent": "",
"Comment": "",
"Created": "2021-11-17T10:38:14.652464384Z",
"Container": "8a038ff17987cf87d4b7d7e2c80cb83bd2474d66e2dd0719e2b4f7de2ad6d853",
"ContainerConfig": {
"Hostname": "8a038ff17987",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {
}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.21.4",
"NJS_VERSION=0.7.0",
"PKG_RELEASE=1~bullseye"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"nginx\" \"-g\" \"daemon off;\"]"
],
"Image": "sha256:2fb4060b053a39040c51ff7eadd30325de2c76650fc50aa42839070e16e8bdcb",
.....此处省略
docker create:创建容器(但是容器不会启动)
[[email protected] ~]# docker create httpd
Unable to find image 'httpd:latest' locally
latest: Pulling from library/httpd
eff15d958d66: Already exists
ba1caf8ba86c: Pull complete
ab86dc02235d: Pull complete
0d58b11d2867: Pull complete
e88da7cb925c: Pull complete
Digest: sha256:1d71eef54c08435c0be99877c408637f03112dc9f929fba3cccdd15896099b02
Status: Downloaded newer image for httpd:latest
8877c16c9c19353c6eb74a93827ed9914fbeb503067d6cc7f1f1e68e4f3ce203
docker rm:删除镜像
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest ad17c88403e2 12 days ago 143MB
nginx latest ea335eea17ab 13 days ago 141MB
[[email protected] ~]# docker rmi ad17c88403e2
Untagged: httpd:latest
Untagged: [email protected]:1d71eef54c08435c0be99877c408637f03112dc9f929fba3cccdd15896099b02
Deleted: sha256:ad17c88403e2cedd27963b98be7f04bd3f903dfa7490586de397d0404424936d
Deleted: sha256:a59e7dfeeb485a8a45b1fcce812b10fbd955d304fa2e9ca43b10b16a8ee1afb8
Deleted: sha256:9592080464aa1890ed187c42a13ecc9f175e975a96a3fad28df0559ad0c08b9d
Deleted: sha256:42d2debfa0c419f7f89affa3e9b62d1b7e54dc6654dbd186d4654ee3661c44c8
Deleted: sha256:136822c50a75392f4ce06461fa4894aa7d1e060ec0dd4782e13e2d9829df50a3
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ea335eea17ab 13 days ago 141MB
docker ps:列出容器
[[email protected] ~]# docker ps // 查看所有运行的容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[[email protected] ~]# docker ps -a // 查看所有容器(运行和非运行的)
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" 21 seconds ago Created infallible_nobel
docker start:启动容器
[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" About a minute ago Created infallible_nobel
[[email protected] ~]# docker start 8877c16c9c19
8877c16c9c19
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" About a minute ago Up 4 seconds 80/tcp infallible_nobel
docker attach:进入容器
在当前shell下attach连接指定运行镜像,以这种方式进入容器,容器会一直占用前台。如果退出容器,容器就会停止运行
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" 2 minutes ago Up 56 seconds 80/tcp infallible_nobel
[[email protected] ~]# docker attach 8877c16c9c19
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker exec:进入容器
这个命令进入容器后台运行就算是退出了容器,容器也不会停止运行
// 启动容器
[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" 4 minutes ago Exited (0) About a minute ago infallible_nobel
[[email protected] ~]# docker start 8877c16c9c19
8877c16c9c19
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" 4 minutes ago Up 3 seconds 80/tcp infallible_nobel
// 进入容器
[[email protected] ~]# docker exec -it 8877c16c9c19 /bin/bash
[email protected]:/usr/local/apache2# ls
bin cgi-bin error icons logs
build conf htdocs include modules
[email protected]:/usr/local/apache2# exit
exit
// 查看容器启动情况
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" 5 minutes ago Up 46 seconds 80/tcp infallible_nobel
docker inspect:查看容器的详细信息
[[email protected] ~]# docker inspect 8877c16c9c19
[
{
"Id": "8877c16c9c19353c6eb74a93827ed9914fbeb503067d6cc7f1f1e68e4f3ce203",
"Created": "2021-12-01T10:06:47.836823243Z",
"Path": "httpd-foreground",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 50995,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-12-01T10:11:23.288419586Z",
"FinishedAt": "2021-12-01T10:10:05.442221306Z"
},
"Image":
......后面省略
docker logs:查看容器日志信息
// 创建容器
[[email protected] ~]# docker create nginx
baac0f280b0a2581ad5c3be233841f0d985d37ca3ecb7c3be5008bca941c9979
[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
baac0f280b0a nginx "/docker-entrypoint.…" 5 seconds ago Created sleepy_mccarthy
8877c16c9c19 httpd "httpd-foreground" 9 minutes ago Up 4 minutes 80/tcp infallible_nobel
// 容器没有运行。无法查看日志信息
[[email protected] ~]# docker logs baac0f280b0a
// 启动容器
[[email protected] ~]# docker start baac0f280b0a
baac0f280b0a
// 查看日志信息
[[email protected] ~]# docker logs baac0f280b0a
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2021/12/01 10:16:51 [notice] 1#1: using the "epoll" event method
2021/12/01 10:16:51 [notice] 1#1: nginx/1.21.4
2021/12/01 10:16:51 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2021/12/01 10:16:51 [notice] 1#1: OS: Linux 4.18.0-257.el8.x86_64
2021/12/01 10:16:51 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2021/12/01 10:16:51 [notice] 1#1: start worker processes
2021/12/01 10:16:51 [notice] 1#1: start worker process 31
2021/12/01 10:16:51 [notice] 1#1: start worker process 32
2021/12/01 10:16:51 [notice] 1#1: start worker process 33
2021/12/01 10:16:51 [notice] 1#1: start worker process 34
2021/12/01 10:16:51 [notice] 1#1: start worker process 35
2021/12/01 10:16:51 [notice] 1#1: start worker process 36
2021/12/01 10:16:51 [notice] 1#1: start worker process 37
2021/12/01 10:16:51 [notice] 1#1: start worker process 38
docker stop:停止容器
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
baac0f280b0a nginx "/docker-entrypoint.…" About a minute ago Up About a minute 80/tcp sleepy_mccarthy
8877c16c9c19 httpd "httpd-foreground" 11 minutes ago Up 6 minutes 80/tcp infallible_nobel
[[email protected] ~]# docker stop baac0f280b0a
baac0f280b0a
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" 11 minutes ago Up 6 minutes 80/tcp infallible_nobel
[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
baac0f280b0a nginx "/docker-entrypoint.…" 2 minutes ago Exited (0) 5 seconds ago sleepy_mccarthy
8877c16c9c19 httpd "httpd-foreground" 11 minutes ago Up 7 minutes 80/tcp infallible_nobel
docker restart:重启容器
[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
baac0f280b0a nginx "/docker-entrypoint.…" 3 minutes ago Exited (0) About a minute ago sleepy_mccarthy
8877c16c9c19 httpd "httpd-foreground" 12 minutes ago Up 8 minutes 80/tcp infallible_nobel
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" 12 minutes ago Up 8 minutes 80/tcp infallible_nobel
[[email protected] ~]# docker restart baac0f280b0a
baac0f280b0a
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
baac0f280b0a nginx "/docker-entrypoint.…" 3 minutes ago Up 2 seconds 80/tcp sleepy_mccarthy
8877c16c9c19 httpd "httpd-foreground" 12 minutes ago Up 8 minutes 80/tcp infallible_nobel
docker kill:杀死正在运行的容器
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
baac0f280b0a nginx "/docker-entrypoint.…" 4 minutes ago Up 40 seconds 80/tcp sleepy_mccarthy
8877c16c9c19 httpd "httpd-foreground" 13 minutes ago Up 8 minutes 80/tcp infallible_nobel
[[email protected] ~]# docker kill 8877c16c9c19
8877c16c9c19
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
baac0f280b0a nginx "/docker-entrypoint.…" 4 minutes ago Up 55 seconds 80/tcp sleepy_mccarthy
docker run:创建容器并直接启动容器.
run命令会先查看本地是否都对应的镜像,如果没有就拉取,然后创建容器,然后运行容器
[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e2ae1f194bd8 httpd "/bin/bash" 37 minutes ago Exited (0) 36 minutes ago hungry_faraday
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest ad17c88403e2 12 days ago 143MB
[[email protected] ~]# docker run -it nginx /bin/bash
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
eff15d958d66: Already exists
1e5351450a59: Pull complete
2df63e6ce2be: Pull complete
9171c7ae368c: Pull complete
020f975acd28: Pull complete
266f639b35ad: Pull complete
Digest: sha256:097c3a0913d7e3a5b01b6c685a60c03632fc7a2b50bc8e35bcaa3691d788226e
Status: Downloaded newer image for nginx:latest
[email protected]:/#
docker rm:删除容器
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
baac0f280b0a nginx "/docker-entrypoint.…" 7 minutes ago Up 4 minutes 80/tcp sleepy_mccarthy
// 无法删除正在运行的容器
[[email protected] ~]# docker rm baac0f280b0a
Error response from daemon: You cannot remove a running container baac0f280b0a2581ad5c3be233841f0d985d37ca3ecb7c3be5008bca941c9979. Stop the container before attempting removal or force remove
// 加上-f可以强制删除正在运行的容器
[[email protected] ~]# docker rm -f baac0f280b0a
baac0f280b0a
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker event state

边栏推荐
- 使用百度EasyDL实现明厨亮灶厨师帽识别
- From Bayesian filter to Kalman filter (I)
- How many of the top ten test tools in 2022 do you master
- [radar] radar signal online sorting based on kernel clustering with matlab code
- Creating new projects and adding your own programs
- JDBC simple encapsulation
- Wechat official account custom sharing and updateappmessagesharedata are all successful. Why is it a link that is shared?
- [image hiding] digital image information hiding system based on DCT, DWT, LHA, LSB, including various attacks and performance parameters, with matlab code
- 用LEX(FLEX)生成PL语言的词法分析器
- SQL audit tool self introduction owls
猜你喜欢

Creating new projects and adding your own programs

Pytorch:交叉熵损失(CrossEntropyLoss)以及标签平滑(LabelSmoothing)的实现

Qt: one signal binds multiple slots

Adobe Flash player 34.0.0.92 and available version modification methods (2021-01-23

Pytest custom hook function

Getting started with QT & OpenGL

【滤波跟踪】基于EKF、时差和频差定位实现目标跟踪附matlab代码

剑指 Offer II 109. 开密码锁

智能合约安全——溢出漏洞

Lookup - lookup of sequential table and ordered table
随机推荐
2022年暑假ACM热身练习3(详细)
RFs self study notes (II): theoretical measurement model - without clutter but with detection probability
搜索问题与技术
Avoidance Adjusted Climbrate
RTC clock: a calendar
三类6种地图可视化软件测评,最好用的工具居然是它
Parity rearrangement of Bm14 linked list
4、 Interface requests data to update input information interactively
Libgdx learning road 02: draw game map with tiled
2、 Uni app login function page Jump
[machine learning] support vector machine classification
VAE:变分自编码器的理解与实现
【图像隐藏】基于DCT、DWT、LHA、LSB的数字图像信息隐藏系统含各类攻击和性能参数附matlab代码
Pytorch GPU yolov5 reports an error
Random finite set RFs self-study notes (6): an example of calculation with the formula of prediction step and update step
ES6's new data container map
[physical application] atmospheric absorption loss with matlab code
More loading in applets (i.e. list paging)
RFs self study notes (4): actual measurement model - the mixture of OK and CK, and then calculate the likelihood probability
JDBC simple encapsulation