三分薄地,认真耕耘

导航

 

4. 容器管理练习

4.1 启动一个nginx和tomcat容器


[root@vms41 ~]# docker run -dit --name=web -p 80:80 --restart=always nginx
a49a7d8df0318e984d9d21bf0a638cadef452bb54707a31b333d8fdd549f1f3a
[root@vms41 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS         PORTS                               NAMES
a49a7d8df031   nginx     "/docker-entrypoint.…"   10 seconds ago   Up 8 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   web
[root@vms41 ~]# docker run -dit --name=web -p 80:8080 --restart=always hub.c.163.com/library/tomcat:latest
181c0a6691bd766f2f5f833a9d1471ac741d1066c7456e192c133fa61d820a25


4.2 docker常用管理命令

docker exec 容器名 命令 ---在容器中临时执行命令
docker stop 容器名 ---停止容器
docker start 容器名 --启动容器
docker restart 容器名 --重启容器
docker logs 容器名 --查看容器日志
docker top 容器名 --查看容器进程运行情况
docker inspect 容器名 --查看容器的详细属性


[root@vms41 ~]# docker run -dit --name=db --restart=always -e MYSQL_ROOT_PASSWORD=haha001 -p 3307:3306 hub.c.163.com/library/mysql:latest
011d27f5bea6fabdeb3a761d0e198b33d9eacb0e9ec780efb8a8c772ed2e4ceb

[root@vms41 ~]# 
[root@vms41 ~]# docker exec db ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
114: eth0@if115: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever

[root@vms41 ~]# docker start db
db
[root@vms41 ~]# docker start db
db       
[root@vms41 ~]# docker restart db
[root@vms41 ~]# docker logs db ##
[root@vms41 ~]# docker top db
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
polkitd             24479               24456               0                   11:33               ?                   00:00:00            mysq
[root@vms41 ~]# docker inspect db | grep -i ipaddress #查看容器的详细信息
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.3",
                    "IPAddress": "172.17.0.3",


posted on 2021-05-09 21:38  平复心态  阅读(103)  评论(0编辑  收藏  举报