关于容器:docker简单使用

55次阅读

共计 2291 个字符,预计需要花费 6 分钟才能阅读完成。

一. 容器应用
tech8 :: ~ » docker pull training/webapp # 载入镜像
tech8 :: ~ » docker run -d -P training/webapp python app.py

-d: 让容器在后盾运行。
-P: 将容器外部应用的网络端口映射到咱们应用的主机上。

tech8 :: ~ » docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cd204fd7b9a2 training/webapp “python app.py” About a minute ago Up About a minute 0.0.0.0:32768->5000/tcp reverent_edison

Docker 凋谢了 5000 端口(默认 Python Flask 端口)映射到主机端口 32769 上
http://127.0.0.1:32768/

咱们也能够通过 -p 参数来设置不一样的端口:
itech8 :: ~ » docker run -d -p 1133:5000 training/webapp python app.py
c5f24273edac8da1b98af344620885888c6361fe5e547fb05a3f540adddfcb0c

http://127.0.0.1:1133/

itech8 :: ~ » docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c5f24273edac training/webapp “python app.py” 18 minutes ago Up 18 minutes 0.0.0.0:1133->5000/tcp frosty_yalow
2e1d9cc9578d training/webapp “python app.py” 20 minutes ago Up 20 minutes 5000/tcp, 0.0.0.0:5000->1133/tcp heuristic_visvesvaraya
cd204fd7b9a2 training/webapp “python app.py” 25 minutes ago Up 25 minutes 0.0.0.0:32768->5000/tcp reverent_edison

查看日志:
itech8 :: ~ » docker logs -f cd204fd7b9a2

  • Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
    172.17.0.1 – – [21/Jun/2019 09:15:10] “GET / HTTP/1.1” 200 –
    172.17.0.1 – – [21/Jun/2019 09:15:11] “GET /favicon.ico HTTP/1.1” 404 –
    172.17.0.1 – – [21/Jun/2019 09:15:26] “GET / HTTP/1.1” 200 –
    172.17.0.1 – – [21/Jun/2019 09:15:27] “GET / HTTP/1.1” 200 –
    172.17.0.1 – – [21/Jun/2019 09:15:54] “GET / HTTP/1.1” 200 –
    172.17.0.1 – – [21/Jun/2019 09:15:55] “GET / HTTP/1.1” 200 –

itech8 :: ~ » docker top heuristic_visvesvaraya
PID USER TIME COMMAND
2536 root 0:00 python app.py

启动利用
docker start heuristic_visvesvaraya
敞开利用
docker stop heuristic_visvesvaraya

移除利用
docker rm heuristic_visvesvaraya

二. 镜像

itech8 :: ~ » docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mongo latest c1d6c06b5775 9 months ago 381MB
training/webapp latest 6fae60ef3446 4 years ago 349MB

training/webapp 是上一步装置的镜像

REPOSITORY:示意镜像的仓库源
TAG:镜像的标签
IMAGE ID:镜像 ID
CREATED:镜像创立工夫
SIZE:镜像大小

搜寻镜像
docker search httpd
装置镜像
docker pull centos/httpd
运行镜像
docker run centos/httpd

容器命名
当咱们创立一个容器的时候,docker 会主动对它进行命名。另外,咱们也能够应用 –name 标识来命名容器,例如
docker run -d -P –name runoob training/webapp python app.py

ansible settle -m raw -a “docker exec -t settle-services tail -5 /var/log/settlement-services/201906/20190621-services.log”

ansible settle -m raw -a “docker exec -t settle-services tail -5 /var/log/settlement-services/201906/20190621-services.log”

ansible settle -m raw -a ‘docker exec -t settle-services tail -5 /var/log/settlement-services/201906/20190621-api.log’
运维:
https://www.w3cschool.cn/auto…

正文完
 0