0
点赞
收藏
分享

微信扫一扫

centos7安装docker攻略

_karen 2022-04-14 阅读 108

centos7安装docker攻略

1.确定linux发行版,比如centos7.6,那么在docker seache centos7.6查询一个系统镜像,下载安装

2.docker exec -i -t 进入容器,安装lnmp环境,导入代码,配置域名等,正常访问

3.docker commit 生成本地镜像

4.上传服务器

我们准备采用centos环境,因此我们先下载个centos镜像,docker search 搜一下都有哪些镜像,我们还可以用tag定义具体的哪个镜像版本,比如search的名字为docker.io/centos ,该镜像可能有多个版本,比如centos的不同版本。如果忽略tags选项,那么默认拉取最新版,如docker pull docker.io/centos:latest 

[root@localhost ~]# docker search centos
INDEX       NAME                                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/centos                             The official build of CentOS.                   5945      [OK]
docker.io   docker.io/ansible/centos7-ansible            Ansible on Centos7                              128                  [OK]
docker.io   docker.io/consol/centos-xfce-vnc             Centos container with "headless" VNC sessi...   114                  [OK]
docker.io   docker.io/jdeathe/centos-ssh                 OpenSSH / Supervisor / EPEL/IUS/SCL Repos ...   114                  [OK]
docker.io   docker.io/centos/mysql-57-centos7            MySQL 5.7 SQL database server                   74
docker.io   docker.io/imagine10255/centos6-lnmp-php56    centos6-lnmp-php56                              58                   [OK]
docker.io   docker.io/tutum/centos                       Simple CentOS docker image with SSH access      45
docker.io   docker.io/centos/postgresql-96-centos7       PostgreSQL is an advanced Object-Relationa...   43
docker.io   docker.io/centos/python-35-centos7           Platform for building and running Python 3...   38
docker.io   docker.io/kinogmt/centos-ssh                 CentOS with SSH                                 29                   [OK]
docker.io   docker.io/pivotaldata/centos-gpdb-dev        CentOS image for GPDB development. Tag nam...   11
docker.io   docker.io/guyton/centos6                     From official centos6 container with full ...   10                   [OK]
docker.io   docker.io/nathonfowlie/centos-jre            Latest CentOS image with the JRE pre-insta...   8                    [OK]
docker.io   docker.io/drecom/centos-ruby                 centos ruby                                     6                    [OK]
docker.io   docker.io/pivotaldata/centos                 Base centos, freshened up a little with a ...   4
docker.io   docker.io/darksheer/centos                   Base Centos Image -- Updated hourly             3                    [OK]
docker.io   docker.io/mamohr/centos-java                 Oracle Java 8 Docker image based on Centos 7    3                    [OK]
docker.io   docker.io/pivotaldata/centos-gcc-toolchain   CentOS with a toolchain, but unaffiliated ...   3
docker.io   docker.io/pivotaldata/centos-mingw           Using the mingw toolchain to cross-compile...   3
docker.io   docker.io/blacklabelops/centos               CentOS Base Image! Built and Updates Daily!     1                    [OK]
docker.io   docker.io/indigo/centos-maven                Vanilla CentOS 7 with Oracle Java Developm...   1                    [OK]
docker.io   docker.io/mcnaughton/centos-base             centos base image                               1                    [OK]
docker.io   docker.io/pivotaldata/centos6.8-dev          CentosOS 6.8 image for GPDB development         0
docker.io   docker.io/pivotaldata/centos7-dev            CentosOS 7 image for GPDB development           0
docker.io   docker.io/smartentry/centos                  centos with smartentry                          0                    [OK]

 搜索指定版本的镜像并下载下来,然后run生成容器。

进入官网:Docker Hub

搜索centos的一个发行版镜像

 

单击centos镜像,查看镜像标签,这里我们下载标签名为centos7.6.1810的版本,命令为docker pull centos:centos7.6.1810,镜像名:标签名如果为latest,那么下载最新版本

docker search命令,也可以查询到镜像仓库的镜像名,但是看不到标签名,所以我们这里来官网看仓库中有哪些centos的版本。

 

 

[root@iZ5361zrqbnxubZ ~]# docker pull centos:centos7.6.1810
centos7.6.1810: Pulling from library/centos
Digest: sha256:0baec775bbf3e01cc770d5823c285b291b44ca05bb7c31b8674db5dae1d2aea9
Status: Image is up to date for centos:centos7.6.1810
[root@iZ5361zrqbnxubZ ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
runoob_new/centos   dev_new             99eaded2c3f8        17 hours ago        191MB
runoob/centos       dev                 99eaded2c3f8        17 hours ago        191MB
runoobwyq/ubuntu    v99                 4006db595534        17 hours ago        137MB
httpd               latest              e77c77f17b46        8 days ago          140MB
nginx               latest              719cd2e3ed04        9 days ago          109MB
centos              6.7                 9f1de3c6ad53        3 months ago        191MB
centos              centos6.7           9f1de3c6ad53        3 months ago        191MB
centos              centos7.6.1810      f1cb7c7d58b7        3 months ago        202MB
centos              latest              9f38484d220f        3 months ago        202MB
hello-world         latest              fce289e99eb9        5 months ago        1.84kB
ubuntu              15.10               9b9cb95443b5        2 years ago         137MB
training/webapp     latest              6fae60ef3446        4 years ago         349MB

[root@iZ5361zrqbnxubZ ~]# docker run -d -it --privileged --name=centoslnmp centos:centos7.6.1810  /usr/sbin/init# 最简单的启动后进入运行状态的语句docker run -dit  centos:centos7.6.1810,也就是docker run -dit 容器名:标签名,这里加入-d是守护进程。该-dit三个参数能保证该容器一直处于运行状态,中途可以使用docker stop或start或restart进行重启停止等,启动后都可以保持run状态。 新建一个容器,此时该容器会自动关闭,因为系统没有前台进程,docker会自动给你将其关闭,详细参见节点【Docker为什么刚运行就退出了?】,因此这里加入了/bin/bash -c 持续输出用于防止这种特性将容器关闭,方便后面使用exec -it 进入运行中的容器进行操作,exec不能进入关闭的容器。或者docker run -d -P --name centos7_lamp centos:centos7.6.1810 /bin/bash -c "while true; do echo hello world; sleep 100; done"

#如果要是用systemctl 管理服务就要加上参数 --privileged 来增加权,并且不能使用默认的/bin/bash,换成/usr/sbin/init。否则当你使用systectl start 服务名,开启一个服务会报错

#Failed to get D-Bus connection: Operation not permitted



 89b91e2652c1b76e10a5e38ce43b772390d67b09f2426ccb79219931d747fdf1
[root@iZ5361zrqbnxubZ ~]# docker ps |grep centos
89b91e2652c1        centos:centos7.6.1810   "/bin/bash -c 'while…"   3 minutes ago       Up 3 minutes                                                         centos7_lamp
[root@iZ5361zrqbnxubZ ~]# docker exec -it centos1 /bin/bash

[root@89b91e2652c1 ]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

安装nginx,修改自动开机启动,生成镜像,镜像文件,传输到另一个服务器,安装镜像。访问。

配置php和mysql

docker run -d -it --privileged --name=centoslnmp10 -p 8110:80  centos7:n /bin/bash systemctl start nginx

docker run -d  --name=centoslnmp10 -p 8110:80 centos7:n /bin/bash systemctl start nginx

systemctl  status nginx

docker exec -it centoslnmp14  /bin/bash

docker run -d --name=centoslnmp14 -p 8112:80 centos7:n /usr/sbin/nginx start

举报

相关推荐

CentOS7安装docker

【centos7安装docker】

centos7 安装docker

CentOS7 安装 Docker

CentOS7安装Docker

CentOS7 安装 docker

0 条评论