Bo's Oracle Station

查看: 2281|回复: 0

课程第34次docker

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2019-6-30 11:31:16 | 显示全部楼层 |阅读模式
安装Docker:
  1. yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
复制代码
  1. yum-config-manager --add-repo https://download1.rpmfusion.org/free/el/updates/7/x86_64/
复制代码
还是在报container-selinux版本低于2.9的错误:
rpm.pbone.net去搜索container-selinux这个包:
1.png

rpm -ivh  container-selinux...rpm

  1. systemctl enable docker
  2. systemctl start docker
复制代码
在文件系统任何地方创建一个文件夹:hello_world
在hello_world里面,写以下文件

Dockerfile文件的内容:

  1. FROM ph</p><p>p:7.3.6-apache
  2. COPY . /var/www/html
  3. EXPOSE 80
复制代码
以php为例,准备一个要测试或者编写的php文件:
index.php:
  1. <?php

  2. echo "Hello World Botang";
复制代码
  1. [root@server3 hello_world]# docker build   ./   -t hello_world
  2. Sending build context to Docker daemon  3.072kB
  3. Step 1/3 : FROM php:7.3.6-apache
  4. 7.3.6-apache: Pulling from library/php
  5. fc7181108d40: Pull complete
  6. 0e65236fc68a: Pull complete
  7. 657b7ad8209d: Pull complete
  8. fe9abd6f2547: Pull complete
  9. 3f3b3b58af14: Pull complete
  10. 6c87b44c0319: Pull complete
  11. 879171658515: Pull complete
  12. 29c3b2e8a58a: Pull complete
  13. c3a25239431e: Pull complete
  14. f297f66a8e1d: Pull complete
  15. 702f5011adeb: Pull complete
  16. ea31bc27c1fb: Pull complete
  17. ad44f5a21cda: Pull complete
  18. Digest: sha256:7fcbf93d7edfe3b524794b4ee9dfa05d973164af0fd233dd8ded7d75ad3dcf99
  19. Status: Downloaded newer image for php:7.3.6-apache
  20. ---> e7d20afcec95
  21. Step 2/3 : COPY .  /var/www/html
  22. ---> 9f44c1d7f18a
  23. Step 3/3 : EXPOSE 80
  24. ---> Running in 766f55b5ddb0
  25. Removing intermediate container 766f55b5ddb0
  26. ---> e0ddd16728ee
  27. Successfully built e0ddd16728ee
  28. Successfully tagged hello_world:latest
  29. [root@server3 hello_world]#
复制代码
运行docker:
  1. [root@server3 hello_world]# docker run -p 80:80 hello_world
复制代码
但是网页改动后,它不会生效, 改成以下这样才更灵活:
  1. [root@server3 hello_world]# docker run -p 80:80   -v  /root/hello_world/:/var/www/html/ hello_world
复制代码

Docker维护命令:



  1. [root@server3 ~]# docker images
  2. REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
  3. hello_world         latest              d8da4120df72        9 hours ago         378MB
  4. php                 7.3.6-apache        e7d20afcec95        2 days ago          378MB
  5. [root@server3 ~]# docker rmi d8da4120df72
  6. Error response from daemon: conflict: unable to delete d8da4120df72 (must be forced) - image is being used by stopped container 3ab31ea2dae1
  7. [root@server3 ~]# docker rm 3ab31ea2dae1
  8. 3ab31ea2dae1
  9. [root@server3 ~]# docker rmi d8da4120df72
  10. Untagged: hello_world:latest
  11. Deleted: sha256:d8da4120df7281f10cac698f14b25709d50084e4bd5d47b6b80dde3673d54512
  12. Deleted: sha256:978cb469a1a5f2efbe96e5987efdc96c02a7b97e6d43d53358c6c7baa6a57c10
  13. Deleted: sha256:b4439c64ff9bc5e5d9608a75ab024a19d91b7d3e2e83d76d22af86777d93cb5f
  14. [root@server3 ~]# docker images
  15. REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
  16. php                 7.3.6-apache        e7d20afcec95        2 days ago          378MB
  17. [root@server3 ~]# docker rmi e7d20afcec95
  18. Untagged: php:7.3.6-apache
  19. Untagged: php@sha256:7fcbf93d7edfe3b524794b4ee9dfa05d973164af0fd233dd8ded7d75ad3dcf99
  20. Deleted: sha256:e7d20afcec952b057a087b4010efd930db2ab9eef8b24934fd6951319f149317
  21. Deleted: sha256:f8d13261fecabf2675329da3a87a3cb34a889d14bf21a1cb971b31c038768df2
  22. Deleted: sha256:f5203bab8d1e014855206d5625c900a8ac51139539930c47fa6501653d23d64f
  23. Deleted: sha256:8403100eb9023d562ab752c57859adc29621ba05a164b66e81e8f91d5b7ed234
  24. Deleted: sha256:7945c278f756bbb73680d3d31d352fc14e3fb0b9786641fa111b5f9ee47279f7
  25. Deleted: sha256:56eaca81820c4640db1272aa5549fe92905cc4a12e578ceac9ecae4e37dfaa49
  26. Deleted: sha256:f80fab9911dbb15595d9fb9047a50d49f8f754cee26dc8af2a9019080fca4813
  27. Deleted: sha256:8f7d2ece04c2c89716da8d613f389d5e0c9ecd1f33aaa681b10362e1534374ea
  28. Deleted: sha256:504256e55285662f1ba462d602356eda40576e30921a17422fdb098fc897f1a1
  29. Deleted: sha256:3bcf4d71f6c0ed0725e7889ba3bc99acf408006cab5a982726e9e17e87650971
  30. Deleted: sha256:796f5d40970c67dd60553847d8244c4de00f5a8616263eef5a4fd8449ff1c215
  31. Deleted: sha256:29960b33853b9f26e7dfe186d785598fdde129204b2163d93c072d0916049ca5
  32. Deleted: sha256:e05e97aed813fc99dec94b1cecc3ff3791e73a5dc40194b027b39f9648d029c6
  33. Deleted: sha256:cf5b3c6798f77b1f78bf4e297b27cfa5b6caa982f04caeb5de7d13c255fd7a1e
  34. [root@server3 ~]# docker images
  35. REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
  36. [root@server3 ~]# docker ps
  37. CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
复制代码




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-11-21 23:54 , Processed in 0.047096 second(s), 27 queries .

快速回复 返回顶部 返回列表