Dockler的基础用法
文章目录
- 一、什么是docker
- 二、OCI&OCF
- 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安装
[root@localhost ~]# cd /etc/yum.repos.d/[root@localhost yum.repos.d]# curl -o docker-ce.repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo[root@localhost yum.repos.d]# sed -i 's@https://download.docker.com@https://mirrors.tuna.tsinghua.edu.cn/docker-ce@g' docker-ce.repo[root@localhost yum.repos.d]# yum -y install docker-ce[root@localhost yum.repos.d]# yum clean all
Failed to set locale, defaulting to C.UTF-8
28 files removed// 启动服务
[root@localhost ~]# systemctl enable --now docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[root@localhost ~]# ls /etc/docker/
key.json
docker加速
docker-ce的配置文件是/etc/docker/daemon.json,此文件默认不存在,需要我们手动创建并进行配置,而docker的加速就是通过配置此文件来实现的。
docker的加速有多种方式:
- docker cn
- 中国科技大学加速器
- 阿里云加速器(需要通过阿里云开发者平台注册帐号,免费使用个人私有的加速器)
加速器服务网址
[root@Docker ~]# 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// 重启
[root@local ~]# systemctl dameon-reload docker
[root@local ~]# 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:查看版本
[root@localhost ~]# docker version
Client: Docker Engine - CommunityVersion: 20.10.11API version: 1.41Go version: go1.16.9Git commit: dea9396Built: Thu Nov 18 00:36:58 2021OS/Arch: linux/amd64Context: defaultExperimental: trueServer: Docker Engine - CommunityEngine:Version: 20.10.11API version: 1.41 (minimum version 1.12)Go version: go1.16.9Git commit: 847da18Built: Thu Nov 18 00:35:20 2021OS/Arch: linux/amd64Experimental: falsecontainerd:Version: 1.4.12GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5drunc:Version: 1.0.2GitCommit: v1.0.2-0-g52b36a2docker-init:Version: 0.19.0GitCommit: de40ad0
docker info:查看系统信息
[root@localhost ~]# docker info
Client:Context: defaultDebug Mode: falsePlugins: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: 0Running: 0Paused: 0Stopped: 0Images: 1Server Version: 20.10.11Storage Driver: overlay2Backing Filesystem: xfsSupports d_type: trueNative Overlay Diff: trueuserxattr: falseLogging Driver: json-fileCgroup Driver: cgroupfsCgroup Version: 1Plugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: inactiveRuntimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5drunc version: v1.0.2-0-g52b36a2init version: de40ad0Security Options:seccompProfile: defaultKernel Version: 4.18.0-257.el8.x86_64Operating System: CentOS Stream 8OSType: linuxArchitecture: x86_64CPUs: 8Total Memory: 3.622GiBName: localhost.localdomainID: FT3B:RKJB:SBUC:OAL7:NW2C:QBTY:6VIW:PWHU:CWBD:PQPU:D424:BZJUDocker Root Dir: /var/lib/dockerDebug Mode: falseRegistry: https://index.docker.io/v1/Labels:Experimental: falseInsecure Registries:127.0.0.0/8Live Restore Enabled: false
docker pull:拉取镜像
[root@localhost ~]# 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:列出系统当前所有镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ea335eea17ab 13 days ago 141MB
docker search:在docker hub中查找镜像
[root@localhost ~]# 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:查看指定镜像的历史记录
[root@localhost ~]# 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:查看指定镜像的详细信息
[root@localhost ~]# docker inspect nginx
[{"Id": "sha256:ea335eea17ab984571cd4a3bcf90a0413773b559c75ef4cda07d0ce952b00291","RepoTags": ["nginx:latest"],"RepoDigests": ["nginx@sha256: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:创建容器(但是容器不会启动)
[root@localhost ~]# 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:删除镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest ad17c88403e2 12 days ago 143MB
nginx latest ea335eea17ab 13 days ago 141MB[root@localhost ~]# docker rmi ad17c88403e2
Untagged: httpd:latest
Untagged: httpd@sha256:1d71eef54c08435c0be99877c408637f03112dc9f929fba3cccdd15896099b02
Deleted: sha256:ad17c88403e2cedd27963b98be7f04bd3f903dfa7490586de397d0404424936d
Deleted: sha256:a59e7dfeeb485a8a45b1fcce812b10fbd955d304fa2e9ca43b10b16a8ee1afb8
Deleted: sha256:9592080464aa1890ed187c42a13ecc9f175e975a96a3fad28df0559ad0c08b9d
Deleted: sha256:42d2debfa0c419f7f89affa3e9b62d1b7e54dc6654dbd186d4654ee3661c44c8
Deleted: sha256:136822c50a75392f4ce06461fa4894aa7d1e060ec0dd4782e13e2d9829df50a3
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ea335eea17ab 13 days ago 141MB
docker ps:列出容器
[root@localhost ~]# docker ps // 查看所有运行的容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES[root@localhost ~]# docker ps -a // 查看所有容器(运行和非运行的)
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" 21 seconds ago Created infallible_nobel
docker start:启动容器
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" About a minute ago Created infallible_nobel[root@localhost ~]# docker start 8877c16c9c19
8877c16c9c19[root@localhost ~]# 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连接指定运行镜像,以这种方式进入容器,容器会一直占用前台。如果退出容器,容器就会停止运行
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" 2 minutes ago Up 56 seconds 80/tcp infallible_nobel[root@localhost ~]# docker attach 8877c16c9c19[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker exec:进入容器
这个命令进入容器后台运行就算是退出了容器,容器也不会停止运行
// 启动容器
[root@localhost ~]# 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[root@localhost ~]# docker start 8877c16c9c19
8877c16c9c19[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" 4 minutes ago Up 3 seconds 80/tcp infallible_nobel// 进入容器
[root@localhost ~]# docker exec -it 8877c16c9c19 /bin/bash
root@8877c16c9c19:/usr/local/apache2# ls
bin cgi-bin error icons logs
build conf htdocs include modules
root@8877c16c9c19:/usr/local/apache2# exit
exit// 查看容器启动情况
[root@localhost ~]# 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:查看容器的详细信息
[root@localhost ~]# 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:查看容器日志信息
// 创建容器
[root@localhost ~]# docker create nginx
baac0f280b0a2581ad5c3be233841f0d985d37ca3ecb7c3be5008bca941c9979[root@localhost ~]# 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// 容器没有运行。无法查看日志信息
[root@localhost ~]# docker logs baac0f280b0a // 启动容器
[root@localhost ~]# docker start baac0f280b0a
baac0f280b0a// 查看日志信息
[root@localhost ~]# 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:停止容器
[root@localhost ~]# 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[root@localhost ~]# docker stop baac0f280b0a
baac0f280b0a[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" 11 minutes ago Up 6 minutes 80/tcp infallible_nobel[root@localhost ~]# 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:重启容器
[root@localhost ~]# 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[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8877c16c9c19 httpd "httpd-foreground" 12 minutes ago Up 8 minutes 80/tcp infallible_nobel[root@localhost ~]# docker restart baac0f280b0a
baac0f280b0a
[root@localhost ~]# 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:杀死正在运行的容器
[root@localhost ~]# 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[root@localhost ~]# docker kill 8877c16c9c19
8877c16c9c19[root@localhost ~]# 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命令会先查看本地是否都对应的镜像,如果没有就拉取,然后创建容器,然后运行容器
[root@localhost ~]# 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[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest ad17c88403e2 12 days ago 143MB[root@localhost ~]# 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
root@421bdeaf3878:/#
docker rm:删除容器
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
baac0f280b0a nginx "/docker-entrypoint.…" 7 minutes ago Up 4 minutes 80/tcp sleepy_mccarthy// 无法删除正在运行的容器
[root@localhost ~]# docker rm baac0f280b0a
Error response from daemon: You cannot remove a running container baac0f280b0a2581ad5c3be233841f0d985d37ca3ecb7c3be5008bca941c9979. Stop the container before attempting removal or force remove// 加上-f可以强制删除正在运行的容器
[root@localhost ~]# docker rm -f baac0f280b0a
baac0f280b0a[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker event state
Dockler的基础用法相关推荐
- Pandas基础用法合集(中文官档)
本节介绍 pandas 数据结构的基础用法.下列代码创建示例数据对象: In [1]: index = pd.date_range('1/1/2000', periods=8) In [2]: s = ...
- Promise基础用法
什么是Promise? Promise是用来处理异步的; Promise就是承诺,对未来的承诺; 所谓的Promise(承诺),里面保存着未来才会结束的事件的结果; Promise是异步编程的一种解决 ...
- pandas object转float_数据分析篇 | Pandas基础用法6【完结篇】
这是最后一篇,至此Pandas系列终于连载完了,有需要的也可以看看前面6篇,尽请收藏. 数据分析篇 | Pandas 概览 数据分析篇 | Pandas基础用法1数据分析篇 | Pandas基础用法2 ...
- dubbo官方文档中文_Pandas中文官方文档:基础用法5
本文授权转载自Python大咖谈禁止二次转载 大家好,我是老表 阅读文本大概需要 16 分钟 建议从头开始学习,本系列前四篇 Pandas中文官方文档:基础用法1 Pandas中文官方文档:基础用法2 ...
- struct用法_精讲响应式webclient第1篇-响应式非阻塞IO与基础用法
笔者在之前已经写了一系列的关于RestTemplate的文章,如下: 精讲RestTemplate第1篇-在Spring或非Spring环境下如何使用 精讲RestTemplate第2篇-多种底层HT ...
- Promise详解(一) ----基础用法
什么是Promise Promise是由社区最早提出并实现的,后加入到es6规范中.为更好处理javascript异步问题,用于解决其多次异步回掉嵌套问题.下面先尝试下promise的基础用法吧. 创 ...
- ORACLE的基础用法
ORACLE的基础用法 转 自:http://blog.163.com/kelly_19831017/blog/static/6196787020083133348873/ sqlplus sys/o ...
- MongoDB 基础用法及学习笔记
MongoDB 基础用法 环境配置与安装 安装 查看MongoDB版本 启动MongoDB服务 检查服务状态 启动服务 打开配置文件,连接MongoDB 查看数据列表 退出 MongoDB 连接 Mo ...
- Python语言学习:python语言的特点、入门、基础用法之详细攻略
Python语言学习:python语言的特点.入门.基础用法之详细攻略 相关内容 Python 基础教程 目录 python语言的特点 python语言的入门 python语言的基础用法 python ...
最新文章
- jQuery插件thickbox在ie下垂直居中问题
- Postfix邮件设定相关
- Delphi7 (第二天:结构及常用函数)
- 蛋花花APP,APP开发这几点你要注意了
- C++ 11 深度学习(五)类型转换:static_cast dynamic_cast const_cast reinterpret_cast
- mysql5.6允许远程服务器访问数据库
- 发货通知单不允许新增,只能关联生成
- 【信息融合】基于matlab BP神经网络和DS证据理论不确定性信息融合问题【含Matlab源码 2112期】
- laravel 框架命令
- 三大框架搭建项目常见问题QA整理
- 【java导出PDF】
- Android 2个Service实现相互保活,通过bindservice来实现,不通过广播实现
- 【调剂】2020西南科技大学微系统中心招收硕士调剂硕士生
- IDEA如何多次启动同一个程序
- 写给大家看的机器学习书【Part3】直观易懂的感知机学习算法PLA
- 《互联网进化论》-破解互联网的奥秘
- 云小朵软件内测分发测试平台说明文档
- iOS14iCloud云盘为何删除文稿和数据不好用_5个特征选择算法,让你的数据处理得心应手...
- 阿里面试官的”说一下从url输入到返回请求的过程“问的难度就是不一样!
- 柯乐义高级弹出菜单(可以有三级菜单)
热门文章
- 微信公众号怎么添加附件?比如word文档,pdf文件等
- js数学运算 取整、取余、取模
- wechat开发errorcode:40164
- 解决MOSS07所在服务器,log文件剧增的办法 、转移日志文件路径
- 开发者边车,命名取自service-mesh的service-sidecar,意为为开发者打辅助的边车工具 通过本地代理的方式将https请求代理到一些国内的加速通道上
- conda 安装 jupyter lab
- linux安装教程心得,安装Linux的五种方法和心得
- DA FMC子卡设计资料yuanlit:FMCJ456-基于JESD204B的2路3GspsAD 2路3Gsps DA FMC子卡
- 工业RFID在自动化控制中的解决方案
- PCI IRQ Routing