统一开发和运维的环境
开发和测试的日常对话:我在我电脑上可以运行~!
一款产品:开发到部署,是两个环境 存在环境的问题?
开发在Windows 发布在Linux…(环境差别很大,而且安装配置麻烦,深有体会~!)
基于Go语言开发的
官网地址
文档地址
Tomcat镜像 --> run --> Tomcat01容器(提供服务)
通过这个模板可以创建多个容器。
Tomcat镜像 --> run --> Tomcat02容器(提供服务)
容器(container)
Docker利用容器技术,独立运行一个或一组应用,这些应用是通过镜像来创建的
仓库(repository)
Docker是一个Client-Server结构的系统,Docker的守护进程运行在主机上。
通过Socket从客户端访问!
DockerServer接收到DockerClient的指令,就会执行这个命令~!
uname -r
[root@sunmmerwind ~]# uname -r
4.18.0-240.15.1.el8_3.x86_64
cat /etc/os-release
[root@sunmmerwind ~]# uname -r
4.18.0-240.15.1.el8_3.x86_64
[root@sunmmerwind ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="8"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
# 直接复制粘贴
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
[root@sunmmerwind ~]# yum install -y yum-utils
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@sunmmerwind ~]# yum install docker-ce docker-ce-cli containerd.io
ce:社区版
ee:企业版(收费)
[root@sunmmerwind ~]# systemctl start docker
[root@sunmmerwind ~]# docker version
Client: Docker Engine - Community
Version: 20.10.6
API version: 1.41
Go version: go1.13.15
Git commit: 370c289
Built: Fri Apr 9 22:44:36 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.6
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 8728dd2
Built: Fri Apr 9 22:43:02 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.4
GitCommit: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
runc:
Version: 1.0.0-rc93
GitCommit: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
docker-init:
Version: 0.19.0
GitCommit: de40ad0
[root@sunmmerwind ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:f2266cbfc127c960fd30e76b7c792dc23b588c0db76233517e1891a4e357d519
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
[root@sunmmerwind ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 6 weeks ago 13.3kB
[root@sunmmerwind ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
58715163d8e3 hello-world "/hello" About a minute ago Exited (0) About a minute ago wonderful_hellman
1)登陆阿里云
2)在弹性计算里面 找到 容器镜像服务
3)免费开通
4)执行下面命令就可以用了
# 创建目录
sudo mkdir -p /etc/docker
# 设置阿里云镜像服务 带最后的EOF
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://noi9j7o6.mirror.aliyuncs.com"]
}
EOF
# 重新加载
sudo systemctl daemon-reload
# 重启Docker
sudo systemctl restart docker
yum remove docker-ce docker-ce-cli containerd.io
rm -rf /var/lib/docker
Client: Docker Engine - Community
Version: 19.03.12
API version: 1.40
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:46:54 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.12
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:45:28 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
Client: Docker Engine - Community
Version: 19.03.12
API version: 1.40
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:46:54 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.12
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:45:28 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
[root@iZbf2jzc4i64zvZ ~]# ^C
[root@iZbf2jzc4i64zvZ ~]# clear
[root@iZbf2jzc4i64zvZ ~]# docker info
Client:
Debug Mode: false
Server:
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 19.03.12
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
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: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1127.10.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.795GiB
Name: iZbf2jzc4i64zvZ
ID: ML25:C7CS:I7GJ:DLJ4:E6ZC:YWOW:VXII:46RU:GUSJ:622O:ZDOG:TXN3
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
Registry Mirrors:
https://noi9j7o6.mirror.aliyuncs.com/
Live Restore Enabled: false
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Options:
-a, --all Show all images (default hides intermediate images)
--digests Show digests
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print images using a Go template
--no-trunc Don't truncate output
-q, --quiet Only show numeric IDs
[root@iZbf2jzc4i64zvZ ~]# docker --help
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/root/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST
env var and default context set with "docker context use")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
builder Manage builds
config Manage Docker configs
container Manage containers
context Manage contexts
engine Manage the docker engine
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Options:
-a, --all Show all images (default hides intermediate images)
--digests Show digests
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print images using a Go template
--no-trunc Don't truncate output
-q, --quiet Only show numeric IDs
镜像类似 我们所说的系统盘 O(∩_∩)O哈哈~
[root@sunmmerwind ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 6 weeks ago 13.3kB
搜索命令
[root@sunmmerwind ~]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 10768 [OK]
mariadb MariaDB Server is a high performing open sou… 4056 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 792 [OK]
percona Percona Server is a fork of the MySQL relati… 533 [OK]
过滤搜索
[root@sunmmerwind ~]# docker search mysql --filter=stars=5000
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 10768 [OK]
[root@sunmmerwind ~]# docker pull mysql
Using default tag: latest #默认下载最新版
latest: Pulling from library/mysql #下载路径
6ec8c9369e08: Pull complete #Linux中的联合文件系统(下载过的 不用重复下载了)
177e5de89054: Pull complete
ab6ccb86eb40: Pull complete
e1ee78841235: Pull complete
09cd86ccee56: Pull complete
78bea0594a44: Pull complete
caf5f529ae89: Pull complete
cf0fc09f046d: Pull complete
4ccd5b05a8f6: Pull complete
76d29d8de5d4: Pull complete
8077a91f5d16: Pull complete
922753e827ec: Pull complete
Digest: sha256:fb6a6a26111ba75f9e8487db639bc5721d4431beba4cd668a4e922b8f8b14acc #签名
Status: Downloaded newer image for mysql:latest #状态:Downloaded 已下载
docker.io/library/mysql:latest #真实下载地址
【所以docker pull mysql 等价于 docker pull docker.io/library/mysql:latest】
删除全部镜像:docker rmi -f $(docker images -aq) #$(删除的参数)
#因为容器中只有一个了
[root@iZbf2jzc4i64zvZ ~]# docker rmi -f $(docker images -aq)
Untagged: hello-world:latest
Untagged: hello-world@sha256:49a1c8800c94df04e9658809b006fd8a686cab8028d33cfba2cc049724254202
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
根据镜像ID删除镜像: docker rmi -f 镜像ID
[root@iZbf2jzc4i64zvZ ~]# docker rmi -f 8679ced16d20
Untagged: mysql:5.7
Untagged: mysql@sha256:97869b42772dac5b767f4e4692434fbd5e6b86bcb8695d4feafb52b59f
Deleted: sha256:8679ced16d206961b35686895b06cfafefde87ef02b518dfc2133081ebf47cda
Deleted: sha256:355f87dc5125a32cc35898a4dde17fb067585bc0d86704b5a467c0ccc0eea484
Deleted: sha256:8299d5c38042216210125535adb2600e46268a0e2b9ec799d12ea5b770236e79
Deleted: sha256:07311a303b2c7cf2ac6992aaf68e12326fe7255985166939cbab7d18b10e0f47
Deleted: sha256:306c9bc1ce2997d000bb6f1ea4108420d9752df93ce39164b7a2f876b954afc4
一次删除多个镜像:docker rmi -f 镜像ID 镜像ID 镜像ID 镜像ID
不做示例了 ID中间加空格就行了~!
根据镜像的名字删除:docker rmi -f 镜像名字
[root@iZbf2jzc4i64zvZ ~]# docker rmi -f mysql
Untagged: mysql:latest
Untagged: mysql@sha256:fb6a6a26111ba75f9e8487db639bc5721d4431beba4cd668a4e922b8f8b14
Deleted: sha256:e3fcc9e1cc046c92cfcea0d66cdb00fcb7747e87dde96dfc958bd80be37af117
Deleted: sha256:7a1c5c1a40dad78bacb211ec3d7918acdd78a76185fd33a167260c3e51e97fa4
Deleted: sha256:abb5f0f890ba2f327d30b5ca1bbc35584bc6357c8d6f4bdc2e4637cce2ea9a35
Deleted: sha256:919c56fc8230b0ddf8580e0a58d34ae1c5e48069d9b48cc41ae7a1cae82bb60e
Deleted: sha256:962d6891622cf4a7e8932f6c76b2c2f3ab9cecb8aad71d55adacc2aece6b0181
Deleted: sha256:ab26019b1328bff5ea5132b5e3f52b9fd3808e734f1a39141fb9e5da561200e2
Deleted: sha256:06bd523b11319c8177ab2003cb31b296cea22b0201bf8ae987ac300118a0654f
Deleted: sha256:a8681d5c66889e97303be147d30eb8ec4b0bd5bc0e2c774b4d94f52ec23c4649
Deleted: sha256:c28ab987d3964139dcd3852e1c10ef0a425d2705c71a3b68b411460279d8535d
Deleted: sha256:c0fc32d1072662668dd59842d893e5ee125c1958931ae84630132b7bb6c09198
Deleted: sha256:da0ebf91b8bc2d545dbe73cbf9b7c7b25df71033f5057133a445e9c33a36ec7d
Deleted: sha256:483d8f607b803b5e3d3f97adbad3b0e692670f223b2529ecae5d04888c29ad5d
Deleted: sha256:95ef25a3204339de1edf47feaa00f60b5ac157a498964790c58c921494ce7ffd
容器类似我们用系统盘 做的新系统~
docker run [可选参数] image
参数说明:–name=“Name” 设置容器名字
-d 后台运行方式
-it 使用交互方式运行,进入容器查看内容
-p(小屁) 指定容器的端口(-p 8080:8080)
-p (ip:主机端口:容器端口)
-p (主机端口:容器端口)【常用】
-p (容器端口)
容器端口 (不写-p)
-P 随机指定端口
# centos 是 下载的一个镜像
[root@iZbf2jzc4i64zvZ ~]# docker run -it centos /bin/bash
# 换成镜像ID了
[root@755709dbc6b0 /]#
# centos基础版本,很多命令不完善!ll命令就没有~~~
[root@755709dbc6b0 /]# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
后台启动命令 及 坑~~!!
#命令:docker run -d 镜像名
[root@iZbf2jzc4i64zvZ ~]# docker run -d centos /bin/bash
27be24a0c1dda2815bc2dec8bb6efc09f81c2b6ca7a9b0380a11e6d6ef315a5b
#问题docker ps,发现centos停止了~
[root@iZbf2jzc4i64zvZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@iZbf2jzc4i64zvZ ~]#
#常见的坑:docker容器使用后台运行,就必须要有一个前台的进程,docker发现没有应用,就会自动停止
#还有nginx,容器后台启动后,发现自己没有提供服务,就会立刻停止
exit
Ctrl+P+Q(顺序不能错)
参数说明:
# 不加任何参数,只显示当前正在运行的容器
-a # 查看当前正在运行的容器 + 历史运行过的程序
-n=? # 显示最近创建的容器(?代表显示几个)
-q # 显示容器的编号(CONTAINER ID)
[root@iZbf2jzc4i64zvZ ~]# docker ps -a -n=1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
755709dbc6b0 centos "/bin/bash" 3 hours ago Exited (0) 3 hours ago pedantic_mccarthy
[root@iZbf2jzc4i64zvZ ~]# docker ps -a -n=2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
755709dbc6b0 centos "/bin/bash" 3 hours ago Exited (0) 3 hours ago pedantic_mccarthy
6b5fb686c28d bf756fb1ae65 "/hello" 35 hours ago Exited (0) 35 hours ago silly_stonebraker
[root@iZbf2jzc4i64zvZ ~]# docker ps -a -n=3
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
755709dbc6b0 centos "/bin/bash" 3 hours ago Exited (0) 3 hours ago pedantic_mccarthy
6b5fb686c28d bf756fb1ae65 "/hello" 35 hours ago Exited (0) 35 hours ago silly_stonebraker
只显示容器编号ID
[root@iZbf2jzc4i64zvZ ~]# docker ps -a -q
755709dbc6b0
6b5fb686c28d
[root@iZbf2jzc4i64zvZ ~]# docker ps -aq
755709dbc6b0
6b5fb686c28d
[root@iZbf2jzc4i64zvZ ~]# docker rm 6b5fb686c28d
6b5fb686c28d
[root@iZbf2jzc4i64zvZ ~]# docker rm 87e99063bbbe
Error response from daemon: You cannot remove a running container 87e99063bbbe.
(在试图移动或强行移动之前,请停止容器)
Stop the container before attempting removal or force remove
[root@iZbf2jzc4i64zvZ ~]# docker rm -f 87e99063bbbe
87e99063bbbe
[root@iZbf2jzc4i64zvZ ~]# docker rm $(docker ps -aq)
de8748047921
755709dbc6b0
[root@iZbf2jzc4i64zvZ ~]# docker ps -a -q|xargs docker rm
e5ad028987ce
docker start 容器ID
docker restart 容器ID
docker stop 容器ID
docker kill 容器ID
参数解释:
-c “” # 引号里面是一段shell脚本
echo # 打印
这就解释了为什么这次后台运行没停止
-tf
–tail 10 显示日志条数(如果不加–tail会全部显示)
[root@iZbf2jzc4i64zvZ ~]# docker run -d centos /bin/bash -c "while true;do echo SummerWind;sleep 1;done" # 这段shell脚本,意思是循环打印SummerWind
c5672e9223d29718ff49ac61be7dbc96bdee87d84f451c24f95fa977ac2b442c
[root@iZbf2jzc4i64zvZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c5672e9223d2 centos "/bin/bash -c 'while猞" 4 seconds ago Up 3 seconds recursing_cartwright
[root@iZbf2jzc4i64zvZ ~]# docker logs -tf --tail 10 c5672e9223d2
2020-07-24T07:15:25.177771117Z SummerWind
2020-07-24T07:15:26.180032231Z SummerWind
2020-07-24T07:15:27.181983254Z SummerWind
2020-07-24T07:15:28.184071541Z SummerWind
2020-07-24T07:15:29.186062819Z SummerWind
docker top 容器ID(这要是正在运行的容器)
[root@iZbf2jzc4i64zvZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b3c259fa54b6 centos "/bin/bash -c 'while猞" About a minute ago Up About a minute hardcore_benz
[root@iZbf2jzc4i64zvZ ~]# docker top b3c259fa54b6
UID PID PPID C STIME TTY TIME CMD
root 17631 17615 0 15:22 ? 00:00:00 /bin/bash -c while true;do echo SummerWind;sleep 1;done
root 17742 17631 0 15:23 ? 00:00:00 /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 1
[root@iZbf2jzc4i64zvZ ~]# docker inspect c5672e9223d2
[
{
#容器ID(这是完整的 显示的只是前12位 ~)
"Id": "c5672e9223d29718ff49ac61be7dbc96bdee87d84f451c24f95fa977ac2b442c",
"Created": "2020-07-24T07:14:37.838659993Z",
"Path": "/bin/bash",
"Args": [
"-c",
"while true;do echo SummerWind;sleep 1;done"
],
#容器状态
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 0,
"ExitCode": 137,
"Error": "",
"StartedAt": "2020-07-24T07:14:38.085351505Z",
"FinishedAt": "2020-07-24T07:20:02.584374216Z"
},
"Image": "sha256:831691599b88ad6cc2a4abbd0e89661a121aff14cfa289ad840fd3946f274f1f",
"ResolvConfPath": "/var/lib/docker/containers/c5672e9223d29718ff49ac61be7dbc96bdee87d84f451c24f95fa977ac2b442c/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/c5672e9223d29718ff49ac61be7dbc96bdee87d84f451c24f95fa977ac2b442c/hostname",
"HostsPath": "/var/lib/docker/containers/c5672e9223d29718ff49ac61be7dbc96bdee87d84f451c24f95fa977ac2b442c/hosts",
"LogPath": "/var/lib/docker/containers/c5672e9223d29718ff49ac61be7dbc96bdee87d84f451c24f95fa977ac2b442c/c5672e9223d29718ff49ac61be7dbc96bdee87d84f451c24f95fa977ac2b442c-json.log",
"Name": "/recursing_cartwright",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/2526bc57fe2854002359d0a0c9eb536460cf1474c70ad0fdd2e8ea215ef7679d-init/diff:/var/lib/docker/overlay2/ff9cceb791db48b712f90809757294fdaf615cb173345e17455dfca4c330c537/diff",
"MergedDir": "/var/lib/docker/overlay2/2526bc57fe2854002359d0a0c9eb536460cf1474c70ad0fdd2e8ea215ef7679d/merged",
"UpperDir": "/var/lib/docker/overlay2/2526bc57fe2854002359d0a0c9eb536460cf1474c70ad0fdd2e8ea215ef7679d/diff",
"WorkDir": "/var/lib/docker/overlay2/2526bc57fe2854002359d0a0c9eb536460cf1474c70ad0fdd2e8ea215ef7679d/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "c5672e9223d2",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash",
"-c",
"while true;do echo SummerWind;sleep 1;done"
],
"Image": "centos",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20200611",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "96108bd4f8742d18781c000c3633d5a384c0927d6b6e4fbc2b6a0e41ab729198",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/96108bd4f874",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "e1e9632f31bacd00015077223d5747f0569d855480fc81e0517c2a52bed39fee",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]
docker cp 容器ID:容器内的目录或文件 主机上的路径
#后台交互运行一个容器
[root@iZbf2jzc4i64zvZ ~]# docker run -it centos /bin/bash
#运行并进入容器
[root@d250d9bba70b /]# [root@iZbf2jzc4i64zvZ ~]#
#容器的文件
[root@d250d9bba70b /]# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[root@d250d9bba70b /]# cd /home/
#进入容器home目录,创建SummerWind.java文件
[root@d250d9bba70b home]# touch SummerWind.java
#显示已经创建
[root@d250d9bba70b home]# ls
SummerWind.java
#退出容器并停止容器
[root@d250d9bba70b home]# exit
exit
#查看运行着的容器 没有
[root@iZbf2jzc4i64zvZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
#查看所有运行过的容器 有【容器在 里面的数据就在,不论是否运行都可以拷贝~~!!!】
[root@iZbf2jzc4i64zvZ ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d250d9bba70b centos "/bin/bash" 2 minutes ago Exited (0) 17 seconds ago upbeat_volhard
#拷贝命令:docker cp 容器ID:容器内的目录或文件 主机上的路径
[root@iZbf2jzc4i64zvZ ~]# docker cp d250d9bba70b:/home/SummerWind.java /home
[root@iZbf2jzc4i64zvZ ~]# cd ..
[root@iZbf2jzc4i64zvZ /]# ls
bin boot dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[root@iZbf2jzc4i64zvZ /]# cd /home
#查看主机上的home文件夹下 已经把容器内的文件拷贝到主机上了
[root@iZbf2jzc4i64zvZ home]# ls
SummerWind.java
docker cp 要拷贝的文件路径 容器名:要拷贝到容器里面对应的路径
# 命令:
docker cp /MyFile/PAIANG.sql bd15ab4384fd:/tmp/
# 容器中查看:
root@bd15ab4384fd:/# cd /tmp/
root@bd15ab4384fd:/tmp# ll
total 90460
drwxrwxrwt 1 root root 4096 Nov 10 14:04 ./
drwxr-xr-x 1 root root 4096 Nov 10 14:04 ../
drwxrwxrwt 2 root root 4096 Feb 14 2019 .oracle/
-rw-r--r-- 1 root root 92616247 Nov 10 13:54 PAIANG.sql
#下载镜像
#运行Nginx容器(镜像要放在最后)
[root@iZbf2jzc4i64zvZ /]# docker run -d --name MyNginx -p 3344:80 nginx
aab1ba8e191cda24e673ca0f61f19c64a74393a685b35e31a0c5401ab3732ccb
[root@iZbf2jzc4i64zvZ /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aab1ba8e191c nginx "/docker-entrypoint.猞" 17 seconds ago Up 15 seconds 0.0.0.0:3344->80/tcp MyNginx
#本地测试 curl,居然还有这?
[root@iZbf2jzc4i64zvZ /]# curl localhost:3344
<!DOCTYPE html>
Welcome to nginx!</title>