# getenforce
Disabled
# systemctl stop firewalld
# yum install -y yum-utils
root:yum.repos.d# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Updating Subscription Management repositories.
Adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
root:yum.repos.d#
root:yum.repos.d# ls -ltr docker-ce.repo
total 296
-rw-r--r--. 1 root root 2081 Jun 27 13:32 docker-ce.repo
# yum list docker-ce --showduplicate
Repository epel is listed more than once in the configuration
Docker CE Stable - x86_64 78 kB/s | 14 kB 00:00
Available Packages
docker-ce.x86_64 3:19.03.13-3.el8 docker-ce-stable
docker-ce.x86_64 3:19.03.14-3.el8 docker-ce-stable
docker-ce.x86_64 3:19.03.15-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.0-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.1-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.2-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.3-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.4-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.5-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.6-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.7-3.el8 docker-ce-stable
# yum install docker-ce -y
# systemctl enable docker
# systemctl start docker
# vi /etc/docker/daemon.json
{
"graph": "/mydata/docker",
"storage-driver": "overlay2",
"insecure-registries": ["registry.access.redhat.com", "quay.io"],
"registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com/"],
"bip": "172.17.0.1/24",
"exec-opts": ["native.cgroupdriver=systemd"],
"live-restore":true
}
[root@iZuf6g4e6vhdv58sz2z1klZ ~]# systemctl restart docker
[root@iZuf6g4e6vhdv58sz2z1klZ ~]# 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.5.1-docker)
scan: Docker Scan (Docker Inc., v0.8.0)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.7
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
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: d71fcd7d8303cbf684402823e425e9dd2e99285d
runc version: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 4.18.0-193.28.1.el8_2.x86_64
Operating System: CentOS Linux 8 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.683GiB
Name: iZuf6g4e6vhdv58sz2z1klZ
ID: T3TJ:BJTA:U5PY:ZX74:K57G:7CDR:RMCT:CSBG:JLFG:FXPQ:KUB6:MVJT
Docker Root Dir: /mydata/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
quay.io
registry.access.redhat.com
127.0.0.0/8
Registry Mirrors:
https://q2gr04ke.mirror.aliyuncs.com/
Live Restore Enabled: true
1. 下载image
# docker pull registry.hub.docker.com/jenkins/jenkins:latest
[root@localhost yum.repos.d]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.hub.docker.com/jenkins/jenkins latest 3e06c7dd3345 14 hours ago 711MB
jenkins/ssh-slave latest fb7b3847769f 6 months ago 514MB
jenkins latest cd14cecfdb3a 2 years ago 696MB
2. 运行创建docker容器
[root@localhost yum.repos.d]# docker run -d -p 8080:8080 -p 50000:50000 -v /jenkinsdata:/var/jenkins_home --name jenkins 3e06c7dd3345
b1649463af54d6bebd4f460cebb70357e168e996730e0ca284923e6c4b1487ab
[root@localhost yum.repos.d]# chown 1000:1000 /jenkinsdata
3. 启动容器
[root@localhost yum.repos.d]# docker start b1649463af54
b1649463af54
[root@localhost yum.repos.d]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b1649463af54 3e06c7dd3345 "/sbin/tini -- /usr/…" 2 minutes ago Up 9 seconds 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp jenkins
[root@localhost yum.repos.d]#
4. 进入容器
[root@localhost yum.repos.d]# docker exec -it b1649463af54 "/bin/bash"
jenkins@b1649463af54:/$
或者:
You can just run an interactive shell container using that image and explore whatever content that image has.
For instance:
docker run -it image_name sh
Or following for images with an entrypoint
docker run -it --entrypoint sh image_name
5. 如何查看image 的dockerfile
if you want to see how the image was build, meaning the steps in its Dockerfile
, you can:
docker image history --no-trunc image_name > image_history
The steps will be logged into the image_history
file.
6. docker的配置文件
The default config file path on Linux is /etc/docker/daemon.json
like you said, but it doesn't exist by default. You can write one yourself and put additional docker daemon configuration stuff in there instead of passing in those configuration options into the command line. You don't even have to do dockerd --config-file /etc/docker/daemon.json
since that's the default path, but it can be useful to make it explicit for others who are inspecting the system.
Also ensure that any configuration you set in /etc/docker/daemon.json
doesn't conflict with options passed into the command line evocation of dockerd
. For reference:
The options set in the configuration file must not conflict with options set via flags. The docker daemon fails to start if an option is duplicated between the file and the flags, regardless their value.
docker 设置容器名称
docker run -d --name 名字 -p 3306:3306 -p 8080:80 镜像名
2.修改容器的名称
a. 通过容器ID 修改
[root@test ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b78a4dd6514d mysql "docker-entrypoint.s…" 2 weeks ago Up 2 days 0.0.0.0:3306->3306/tcp, 33060/tcp mysql-server
[root@test ~]# docker rename b78a4dd6514d mysql8.0
[root@test ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b78a4dd6514d mysql "docker-entrypoint.s…" 2 weeks ago Up 2 days 0.0.0.0:3306->3306/tcp, 33060/tcp mysql8.0
b. 通过容器名字修改:
docker rename 原容器名称 新容器名称
[shensh@cnwbzp3137 ~]$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1ad37d852c16 centos/centos-postfix:v0.7 "smtp-run.sh" 42 hours ago Up 42 hours 0.0.0.0:2500->25/tcp trusting_maxwell
53574636d570 centos/centos-httpd:v0.4 "httpd-foreground" 44 hours ago Up 44 hours 0.0.0.0:4433->443/tcp friendly_williamson
[shensh@cnwbzp3137 ~]$ sudo docker rename trusting_maxwell centos-postfix
[sudo] password for shensh:
[shensh@cnwbzp3137 ~]$
[shensh@cnwbzp3137 ~]$ sudo docker rename friendly_williamson centos-rcphttpd
[shensh@cnwbzp3137 ~]$
3. 查看容器信息:
inspect Return low-level information on a container or image #查看容器详细信息
[root@cnwbzp3137 ~]# docker inspect 8a9d4955d14c
[
{
"Id": "8a9d4955d14c2da2aae02d9ce20f7d4461d74551f0ae35c363bc62d63ef56e2d",
"Created": "2022-03-01T12:20:35.546836128Z",
"Path": "/usr/bin/supervisord",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 5382,
"ExitCode": 0,
"Error": "",
"StartedAt": "2022-03-12T11:13:29.00933831Z",
导出和导入镜像:
# docker save centos > /opt/centos.tar.gz # 导出docker镜像至本地
# docker load < /opt/centos.tar.gz #导入本地镜像到docker镜像库
docker镜像开机自动启动
网上有些文章说,要让docker 的容器自动在开机启动,是写脚本,比如在 rc.local 中写。
其实完全没必要这么麻烦,docker 有相关指令,docker run 指令中加入 --restart=always 就行。
sudo docker run --restart=always .....
如果创建时未指定 --restart=always ,可通过update 命令设置
docker update --restart=always xxx
第一次拉取启动完镜像,然后重启系统,发现镜像都没启动,解决办法就是设置自动启动,如下
1. 查看所有安装的镜像
-
[root@localhost ~]# docker ps -a
-
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
-
cef8c24d12fe logstash:5.6.15 "/docker-entrypoint.…" 16 hours ago Exited (255) 13 minutes ago 0.0.0.0:4560->4560/tcp
-
e1154d32d3f5 kibana:5.6.11 "/docker-entrypoint.…" 16 hours ago Exited (255) 13 minutes ago
2.设置总是自动启动
-
[root@localhost ~]# docker update cef8c24d12fe --restart=always
-
cef8c24d12fe
-
[root@localhost ~]# docker update e1154d32d3f5 --restart=always
-
e1154d32d3f5
3. 直接重启系统就行,发现已经启动了
-
[root@localhost ~]# docker ps
-
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
-
cef8c24d12fe logstash:5.6.15 "/docker-entrypoint.…" 16 hours ago Up 2 minutes 0.0.0.0:4560->4560/tcp logstash
-
e1154d32d3f5 kibana:5.6.11 "/docker-entrypoint.…" 16 hours ago Up 2 minutes kibana
操作例子:
[shensh@cnwbzp3137 mydockerfile]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos/centos-postfix v0.8 dc36d82efc61 30 minutes ago 414MB
[shensh@cnwbzp3137 mydockerfile]$ sudo docker run -itd --name centos-postfix --restart=always -p 2500:25 --hostname=report-postfix centos/centos-postfix:v0.8
3b937aafd3e54c2457ec2cc9cc4682f340972229377820bd3e0fd88713931a7c
[shensh@cnwbzp3137 mydockerfile]$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3b937aafd3e5 centos/centos-postfix:v0.8 "smtp-run.sh" 14 seconds ago Up 13 seconds 0.0.0.0:2500->25/tcp centos-postfix
[shensh@cnwbzp3137 mydockerfile]$ sudo docker exec -it 3b937aafd3e5 /bin/bash
[root@report-postfix /]#
利用现有container制作镜像:
[root@cnwbzp3137 dockfile]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d860115e81e7 centos/centos-httpd:v0.8 "httpd-foreground" 4 minutes ago Up 4 minutes 0.0.0.0:4433->443/tcp centos-rcphttpd
fa9ba486406e centos/centos-postfix:v0.7 "smtp-run.sh" 7 months ago Up 4 weeks 127.0.0.1:2500->25/tcp centos-postfix
f2dbfd390b80 eccube/mysql51:latest "docker-entrypoint.s…" 7 months ago Up 4 weeks 0.0.0.0:3312->3306/tcp webpage-db
[root@cnwbzp3137 dockfile]# docker commit d860115e81e7 centos/centos-httpd:v1.0
sha256:7f5b076d1e0ee52254ab21442655bfc95876170751aad1d23d07c73a3d8479c6
[root@cnwbzp3137 dockfile]#
以这个镜像做一些小更改, 启用supervisord 来启动多进程:
[root@cnwbzp3137 dockfile]# cat Dockerfile
FROM centos/centos-httpd:v1.0
CMD ["/usr/bin/supervisord"]
[root@cnwbzp3137 dockfile]# docker build -t centos/centos-httpd:v1.1 .
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM centos/centos-httpd:v1.0
---> 7f5b076d1e0e
Step 2/2 : CMD ["/usr/bin/supervisord"]
---> Running in 3d7f66a28606
Removing intermediate container 3d7f66a28606
---> 1fbe5c51cf66
Successfully built 1fbe5c51cf66
Successfully tagged centos/centos-httpd:v1.1
[root@cnwbzp3137 dockfile]#
[root@cnwbzp3137 dockfile]# docker run -itd --name centos-rcphttpd --restart=always --link webpage-db -p 4433:443 -v /usr/local/rcpreport/www:/var/www -v /usr/local/rcpreport/httpd:/etc/httpd centos/centos-httpd:v1.1
163f49a72874ce0b7299117bd1686803eb47462fd50d55449e4d00654387c1f7
[root@cnwbzp3137 dockfile]#
[root@cnwbzp3137 dockfile]#
[root@cnwbzp3137 dockfile]#
[root@cnwbzp3137 dockfile]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
163f49a72874 centos/centos-httpd:v1.1 "/usr/bin/supervisord" 7 seconds ago Up 6 seconds 0.0.0.0:4433->443/tcp centos-rcphttpd
fa9ba486406e centos/centos-postfix:v0.7 "smtp-run.sh" 7 months ago Up 4 weeks 127.0.0.1:2500->25/tcp centos-postfix
f2dbfd390b80 eccube/mysql51:latest "docker-entrypoint.s…" 7 months ago Up 4 weeks 0.0.0.0:3312->3306/tcp webpage-db
faf7d258d748 deploycompose_db "docker-entrypoint.s…" 8 months ago Up 4 weeks 0.0.0.0:3306->3306/tcp, 33060/tcp dst-mysql
54fa3f24fe28 deploycompose_nginx "/docker-entrypoint.…" 8 months ago Up 4 weeks 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp dst-nginx
d646ec03b5b2 deploycompose_rabbitmq "docker-entrypoint.s…" 8 months ago Up 4 weeks 4369/tcp, 5671-5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp dst-rabbitmq
ab0eb9e3cc0c deploycompose_sp "supervisord -c supe…" 8 months ago Up 4 weeks 80/tcp dst-sp
33efbe76c145 deploycompose_kdb "supervisord -c supe…" 8 months ago Up 4 weeks 80/tcp dst-kdb
f04b71892b7b portainer/portainer "/portainer" 2 years ago Up 4 weeks 0.0.0.0:9000->9000/tcp portainer
[root@cnwbzp3137 dockfile]# docker exec -it 163f49a72874 /bin/bash
[root@163f49a72874 /]#
[root@163f49a72874 /]#
[root@163f49a72874 /]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 19:10 pts/0 00:00:00 /usr/bin/python /usr/bin/supervisord
root 6 1 1 19:10 pts/0 00:00:00 httpd -DFOREGROUND
root 17 1 0 19:10 ? 00:00:00 crond
root 19 6 0 19:10 pts/0 00:00:00 /usr/sbin/nss_pcache 1 off /etc/httpd/alias
apache 22 6 0 19:10 pts/0 00:00:00 httpd -DFOREGROUND
apache 23 6 0 19:10 pts/0 00:00:00 httpd -DFOREGROUND
apache 24 6 0 19:10 pts/0 00:00:00 httpd -DFOREGROUND
apache 25 6 0 19:10 pts/0 00:00:00 httpd -DFOREGROUND
apache 26 6 0 19:10 pts/0 00:00:00 httpd -DFOREGROUND
apache 27 6 0 19:10 pts/0 00:00:00 httpd -DFOREGROUND
apache 28 6 0 19:10 pts/0 00:00:00 httpd -DFOREGROUND
apache 29 6 0 19:10 pts/0 00:00:00 httpd -DFOREGROUND
root 48 0 1 19:10 pts/1 00:00:00 /bin/bash
root 61 48 0 19:10 pts/1 00:00:00 ps -ef
[root@163f49a72874 /]#
[root@163f49a72874 /]# cd /var/www/vhosts/reporting.linux.com/clients/cirats
[root@163f49a72874 cirats]# ls -ltr
total 96
-rw------- 1 apache apache 213 Jul 21 2021 connect.php
[root@163f49a72874 cirats]# cat connect.php
<?php
$host="webpage-db";
$db_user="";
$db_pass="";
$db_name="SrvInformation";
$db_port="3306";
$link=mysqli_connect($host,$db_user,$db_pass,$db_name,$db_port);
mysqli_query($link,"SET names UTF8");
?>
[root@163f49a72874 cirats]#
删除镜像:
[root@cnwbzp3137 dockfile]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos/centos-httpd v1.1 1fbe5c51cf66 7 minutes ago 952MB
centos/centos-httpd v1.0 7f5b076d1e0e 12 minutes ago 952MB
centos/centos-httpd v0.9 d1f248be5212 27 minutes ago 931MB
centos/centos-httpd v0.8 230c9aa4ba49 56 minutes ago 931MB
centos/centos-postfix v0.8 a671b18fbe65 5 months ago 291MB
centos/centos-httpd v0.7 37f7d633b938 5 months ago 871MB
centos/centos-httpd v0.6 83e083f56186 7 months ago 786MB
centos/centos-postfix v0.7 e9a4fe653283 7 months ago 291MB
centos/centos-httpd v0.4 43479caf73b3 7 months ago 698MB
eccube/mysql51 latest 2f95c784f6b6 5 years ago 331MB
[root@cnwbzp3137 dockfile]#
[root@cnwbzp3137 dockfile]#
[root@cnwbzp3137 dockfile]# docker rmi centos/centos-httpd:v1.0 centos/centos-httpd:v0.9
Untagged: centos/centos-httpd:v1.0
Untagged: centos/centos-httpd:v0.9
Deleted: sha256:d1f248be5212ba2e2a14971bcac17b3f75e84a966c5633d7ec6d0a4ef9005e22
[root@cnwbzp3137 dockfile]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos/centos-httpd v1.1 1fbe5c51cf66 11 minutes ago 952MB
centos/centos-httpd v0.8 230c9aa4ba49 59 minutes ago 931MB
centos/centos-postfix v0.8 a671b18fbe65 5 months ago 291MB
centos/centos-httpd v0.7 37f7d633b938 5 months ago 871MB
centos/centos-httpd v0.6 83e083f56186 7 months ago 786MB
centos/centos-postfix v0.7 e9a4fe653283 7 months ago 291MB
centos/centos-httpd v0.4 43479caf73b3 7 months ago 698MB
eccube/mysql51 latest 2f95c784f6b6 5 years ago 331MB
[root@cnwbzp3137 dockfile]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
163f49a72874 centos/centos-httpd:v1.1 "/usr/bin/supervisord" 10 minutes ago Up 10 minutes 0.0.0.0:4433->443/tcp centos-rcphttpd
fa9ba486406e centos/centos-postfix:v0.7 "smtp-run.sh" 7 months ago Up 4 weeks 127.0.0.1:2500->25/tcp centos-postfix
f2dbfd390b80 eccube/mysql51:latest "docker-entrypoint.s…" 7 months ago Up 4 weeks 0.0.0.0:3312->3306/tcp webpage-db
faf7d258d748 deploycompose_db "docker-entrypoint.s…" 8 months ago Up 4 weeks 0.0.0.0:3306->3306/tcp, 33060/tcp dst-mysql
54fa3f24fe28 deploycompose_nginx "/docker-entrypoint.…" 8 months ago Up 4 weeks 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp dst-nginx
d646ec03b5b2 deploycompose_rabbitmq "docker-entrypoint.s…" 8 months ago Up 4 weeks 4369/tcp, 5671-5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp dst-rabbitmq
ab0eb9e3cc0c deploycompose_sp "supervisord -c supe…" 8 months ago Up 4 weeks 80/tcp dst-sp
33efbe76c145 deploycompose_kdb "supervisord -c supe…" 8 months ago Up 4 weeks 80/tcp dst-kdb
f04b71892b7b portainer/portainer "/portainer" 2 years ago Up 4 weeks 0.0.0.0:9000->9000/tcp portainer
基于centos 6.10 创建的httpd 镜像:
制作httpd 启动脚本:
[root@localhost dockerfile]# cat httpd-foreground
#!/bin/bash
set -e
# Apache gets grumpy about PID files pre-existing
rm -f /var/run/httpd/httpd.pid
exec httpd -DFOREGROUND
制作docker file
[root@localhost dockerfile]# cat Dockerfile
FROM centos/centos-httpd:latest
MAINTAINER shensh@cn.ibm.com
COPY mod_jk.so /usr/lib64/httpd/modules
RUN chmod 755 /usr/lib64/httpd/modules/mod_jk.so
RUN chown root:root /usr/lib64/httpd/modules/mod_jk.so
EXPOSE 443
COPY httpd-foreground /usr/bin/
CMD ["httpd-foreground"]
[root@localhost dockerfile]#
[root@localhost dockerfile]# docker build -t centos/centos-httpd:v0.4 .
Sending build context to Docker daemon 1.98GB
Step 1/8 : FROM centos/centos-httpd:latest
---> 3ad3931ae723
Step 2/8 : MAINTAINER shensh@cn.ibm.com
---> Using cache
---> da1656d90d0c
Step 3/8 : COPY mod_jk.so /usr/lib64/httpd/modules
---> 5f3d4dc0979f
Step 4/8 : RUN chmod 755 /usr/lib64/httpd/modules/mod_jk.so
---> Running in 80de43040466
Removing intermediate container 80de43040466
---> 82b70dc861e1
Step 5/8 : RUN chown root:root /usr/lib64/httpd/modules/mod_jk.so
---> Running in 566acccfc9a5
Removing intermediate container 566acccfc9a5
---> fa52ca0ef730
Step 6/8 : EXPOSE 443
---> Running in 72ab00982974
Removing intermediate container 72ab00982974
---> 1f74b0b50778
Step 7/8 : COPY httpd-foreground /usr/bin/
---> 2860ebcad32e
Step 8/8 : CMD ["httpd-foreground"]
---> Running in d44331d300e1
Removing intermediate container d44331d300e1
---> 43479caf73b3
Successfully built 43479caf73b3
Successfully tagged centos/centos-httpd:v0.4
[root@localhost dockerfile]#
[root@localhost dockerfile]#
当docker以后台进程方式跑,退出容器,容器也会继续运行
[shensh@cnwbzp3137 cirats]$ sudo docker run -itd --name centos-rcphttpd --restart=always --link webpage-db -p 4433:443 -v /usr/local/rcpreport/www:/var/www -v /usr/local/rcpreport/httpd:/etc/httpd centos/centos-httpd:v0.7
bf9283e39353668d0c2d5d4c1c11657f64026bf1ae4e4c4f4f7570f13dd94dda
[shensh@cnwbzp3137 ~]$
[shensh@cnwbzp3137 ~]$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
72e7e9b42bbf centos/centos-httpd:v0.7 "httpd-foreground" 8 seconds ago Up 6 seconds 0.0.0.0:4433->443/tcp centos-rcphttpd
进入容器:
[root@localhost dockerfile]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2a5837669533 centos/centos-httpd:v0.4 "httpd-foreground" 17 seconds ago Up 16 seconds 0.0.0.0:443->443/tcp, :::443->443/tcp charming_thompson
[root@localhost dockerfile]#
[root@localhost dockerfile]# docker exec -it 2a5837669533 /bin/bash
[root@2a5837669533 /]#
[root@localhost dockerfile]# docker exec -it cbd3ec34952c /bin/bash
[root@cbd3ec34952c /]# ps -ef|grep httpd
root 1 0 0 00:00 pts/0 00:00:00 httpd -DFOREGROUND
root 8 1 0 00:00 pts/0 00:00:00 /usr/sbin/nss_pcache 1 off /etc/httpd/alias
apache 11 1 0 00:00 pts/0 00:00:00 httpd -DFOREGROUND
apache 12 1 0 00:00 pts/0 00:00:00 httpd -DFOREGROUND
apache 13 1 0 00:00 pts/0 00:00:00 httpd -DFOREGROUND
apache 14 1 0 00:00 pts/0 00:00:00 httpd -DFOREGROUND
apache 15 1 0 00:00 pts/0 00:00:00 httpd -DFOREGROUND
apache 16 1 0 00:00 pts/0 00:00:00 httpd -DFOREGROUND
apache 17 1 0 00:00 pts/0 00:00:00 httpd -DFOREGROUND
apache 18 1 0 00:00 pts/0 00:00:00 httpd -DFOREGROUND
root 51 36 0 00:10 pts/1 00:00:00 grep httpd
[root@cbd3ec34952c /]# netstat -tuanp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1/httpd
tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 1/httpd
退出容器:
[root@cbd3ec34952c /]#
[root@cbd3ec34952c /]# exit
exit
容器还在运行:
[root@localhost dockerfile]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cbd3ec34952c centos/centos-httpd:v0.4 "httpd-foreground" 5 minutes ago Up 5 minutes 443/tcp dazzling_brown
如果要结束容器运行,可以下以下指令:
[root@localhost dockerfile]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cbd3ec34952c centos/centos-httpd:v0.4 "httpd-foreground" 11 minutes ago Up 11 minutes 443/tcp dazzling_brown
[root@localhost dockerfile]#
[root@localhost dockerfile]# docker stop cbd3ec34952c
cbd3ec34952c
[root@localhost dockerfile]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
rm Remove one or more containers #移除一个或者多个容器
[root@cnwbzp3137 dockfile]# docker rm bf9283e39353
bf9283e39353
[root@cnwbzp3137 dockfile]#
查看容器的方法:
查看运行中的容器:
[root@localhost dockerfile]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2a5837669533 centos/centos-httpd:v0.4 "httpd-foreground" 4 hours ago Up 4 hours 0.0.0.0:443->443/tcp, :::443->443/tcp charming_thompson
[root@localhost dockerfile]#
[root@localhost dockerfile]#
查看所有的容器:
[root@localhost dockerfile]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2a5837669533 centos/centos-httpd:v0.4 "httpd-foreground" 4 hours ago Up 4 hours 0.0.0.0:443->443/tcp, :::443->443/tcp charming_thompson
cbd3ec34952c centos/centos-httpd:v0.4 "httpd-foreground" 4 hours ago Exited (0) 4 hours ago dazzling_brown
54148e4efc4b centos/centos-httpd:v0.4 "/bin/bash" 4 hours ago Exited (0) 4 hours ago hopeful_curie
ea922d330e7c centos/centos-httpd:v0.3 "/bin/bash" 12 hours ago Exited (137) 4 hours ago affectionate_blackburn
9f19fb9ade87 centos/centos-httpd:v0.3 "httpd-foreground" 12 hours ago Exited (1) 12 hours ago kind_lewin
886170efbb90 centos/centos-httpd:v0.3 "/bin/bash" 12 hours ago Exited (137) 12 hours ago condescending_jennings
f06da1f8d398 centos/centos-httpd:v0.3 "httpd-foreground" 12 hours ago Exited (1) 12 hours ago thirsty_lehmann
e580a6879659 centos/centos-httpd:v0.2 "/bin/sh -c '/usr/sb…" 13 hours ago Exited (137) 12 hours ago silly_mcnulty
10713a64194b centos/centos-httpd:v0.2 "/bin/sh -c '/usr/sb…" 13 hours ago Exited (137) 13 hours ago eloquent_burnell
27e65f43cd7b centos/centos-httpd:v0.2 "/bin/sh -c '/usr/sb…" 13 hours ago Exited (137) 13 hours ago goofy_sinoussi
1abb8d12d134 centos/centos-httpd:v0.2 "/bin/sh -c '/usr/sb…" 13 hours ago Exited (137) 13 hours ago vigilant_satoshi
aa49c3d29a3f centos/centos-httpd:v0.2 "/bin/sh -c '/usr/sb…" 13 hours ago Exited (137) 13 hours ago clever_fermi
1bf53644f4da centos/centos-httpd:latest "/bin/bash" 13 hours ago Exited (0) 13 hours ago wonderful_mcnulty
30bc61600e14 centos/centos-httpd:v0.1 "/etc/init.d/httpd /…" 13 hours ago Exited (2) 13 hours ago competent_khayyam
15b97e91a9a0 centos/centos-httpd:v0.1 "/etc/init.d/httpd s…" 13 hours ago Exited (0) 13 hours ago objective_hodgkin
9a54a308bc3a centos/centos-httpd:v0.1 "/etc/init.d/httpd /…" 13 hours ago Exited (2) 13 hours ago sad_chatterjee
966ed05890ee 4d72c621139e "/etc/init.d/httpd /…" 14 hours ago Exited (2) 14 hours ago dreamy_chebyshev
45929ca4e543 centos/centos-httpd "/bin/bash" 15 hours ago Exited (137) 14 hours ago beautiful_mayer
f81643395f34 b9e14a516631 "/bin/bash" 26 hours ago Exited (127) 16 hours ago trusting_jang
353688de8708 b9e14a516631 "/bin/bash" 38 hours ago Exited (0) 27 hours ago gallant_tereshkova
78b10365c155 48650444e419 "/bin/bash" 39 hours ago Exited (0) 38 hours ago angry_gates
14d13ce4054e 48650444e419 "/bin/bash" 39 hours ago Exited (0) 39 hours ago flamboyant_robinson
d3926c68e5c6 centos/httpd "/bin/bash" 40 hours ago Exited (0) 40 hours ago wizardly_borg
5e91dd3cdcae httpd "/bin/bash" 40 hours ago Exited (0) 40 hours ago eloquent_proskuriakova
[root@localhost dockerfile]#
也可以用docker ps
[root@localhost dockerfile]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2a5837669533 centos/centos-httpd:v0.4 "httpd-foreground" 4 hours ago Up 4 hours 0.0.0.0:443->443/tcp, :::443->443/tcp charming_thompson
[root@localhost dockerfile]#
[root@localhost dockerfile]#
[root@localhost dockerfile]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2a5837669533 centos/centos-httpd:v0.4 "httpd-foreground" 4 hours ago Up 4 hours 0.0.0.0:443->443/tcp, :::443->443/tcp charming_thompson
cbd3ec34952c centos/centos-httpd:v0.4 "httpd-foreground" 4 hours ago Exited (0) 4 hours ago dazzling_brown
54148e4efc4b centos/centos-httpd:v0.4 "/bin/bash" 4 hours ago Exited (0) 4 hours ago hopeful_curie
ea922d330e7c centos/centos-httpd:v0.3 "/bin/bash" 12 hours ago Exited (137) 4 hours ago affectionate_blackburn
9f19fb9ade87 centos/centos-httpd:v0.3 "httpd-foreground" 12 hours ago Exited (1) 12 hours ago kind_lewin
886170efbb90 centos/centos-httpd:v0.3 "/bin/bash" 12 hours ago Exited (137) 12 hours ago condescending_jennings
f06da1f8d398 centos/centos-httpd:v0.3 "httpd-foreground" 12 hours ago Exited (1) 12 hours ago thirsty_lehmann
e580a6879659 centos/centos-httpd:v0.2 "/bin/sh -c '/usr/sb…" 13 hours ago Exited (137) 12 hours ago silly_mcnulty
10713a64194b centos/centos-httpd:v0.2 "/bin/sh -c '/usr/sb…" 13 hours ago Exited (137) 13 hours ago eloquent_burnell
27e65f43cd7b centos/centos-httpd:v0.2 "/bin/sh -c '/usr/sb…" 13 hours ago Exited (137) 13 hours ago goofy_sinoussi
1abb8d12d134 centos/centos-httpd:v0.2 "/bin/sh -c '/usr/sb…" 13 hours ago Exited (137) 13 hours ago vigilant_satoshi
aa49c3d29a3f centos/centos-httpd:v0.2 "/bin/sh -c '/usr/sb…" 13 hours ago Exited (137) 13 hours ago clever_fermi
1bf53644f4da centos/centos-httpd:latest "/bin/bash" 13 hours ago Exited (0) 13 hours ago wonderful_mcnulty
30bc61600e14 centos/centos-httpd:v0.1 "/etc/init.d/httpd /…" 13 hours ago Exited (2) 13 hours ago competent_khayyam
15b97e91a9a0 centos/centos-httpd:v0.1 "/etc/init.d/httpd s…" 13 hours ago Exited (0) 13 hours ago objective_hodgkin
9a54a308bc3a centos/centos-httpd:v0.1 "/etc/init.d/httpd /…" 14 hours ago Exited (2) 14 hours ago sad_chatterjee
966ed05890ee 4d72c621139e "/etc/init.d/httpd /…" 14 hours ago Exited (2) 14 hours ago dreamy_chebyshev
45929ca4e543 centos/centos-httpd "/bin/bash" 15 hours ago Exited (137) 14 hours ago beautiful_mayer
f81643395f34 b9e14a516631 "/bin/bash" 26 hours ago Exited (127) 16 hours ago trusting_jang
353688de8708 b9e14a516631 "/bin/bash" 38 hours ago Exited (0) 27 hours ago gallant_tereshkova
78b10365c155 48650444e419 "/bin/bash" 39 hours ago Exited (0) 38 hours ago angry_gates
14d13ce4054e 48650444e419 "/bin/bash" 40 hours ago Exited (0) 39 hours ago flamboyant_robinson
d3926c68e5c6 centos/httpd "/bin/bash" 40 hours ago Exited (0) 40 hours ago wizardly_borg
5e91dd3cdcae httpd "/bin/bash" 40 hours ago Exited (0) 40 hours ago eloquent_proskuriakova
只打开特定的接口来转发端口: 比如只使用loop接口 监听 端口
[shensh@cnwbzp3137 ~]$ sudo docker run -itd --name centos-postfix --restart=always -p 127.0.0.1:2500:25 --hostname=report-postfix.ibm.com centos/centos-postfix:v0.7
fa9ba486406efe7c48e68d24eb2be31a55be9aa287750b1bccf6d068bf2b963e
[shensh@cnwbzp3137 ~]$
[shensh@cnwbzp3137 ~]$
[shensh@cnwbzp3137 ~]$
[shensh@cnwbzp3137 ~]$
[shensh@cnwbzp3137 ~]$
[shensh@cnwbzp3137 ~]$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fa9ba486406e centos/centos-postfix:v0.7 "smtp-run.sh" 7 seconds ago Up 5 seconds 127.0.0.1:2500->25/tcp
[shensh@cnwbzp3137 ~]$ sudo netstat -tulnp|grep 25
tcp 0 0 127.0.0.1:2500 0.0.0.0:* LISTEN 24311/docker-proxy
[shensh@cnwbzp3137 ~]$