转 Linux 上Docker的安装与使用入门

https://blog.csdn.net/powerccna/article/details/77897693

  1. 安装Docker
    [plain] view plain copy
    yum install docker.x86_64

  2. 启动Docker
    [plain] view plain copy
    service docker start
    把Docker 加入到开机自启动
    chkconfig docker on

  3. 去docker 仓库查找image
    [plain] view plain copy
    [root@ ~]# docker search centos
    INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
    docker.io docker.io/centos The official build of CentOS. 3827 [OK]
    docker.io docker.io/ansible/centos7-ansible Ansible on Centos7 103 [OK]
    docker.io docker.io/jdeathe/centos-ssh CentOS-6 6.9 x86_64 / CentOS-7 7.4.1708 x8… 90 [OK]
    docker.io docker.io/tutum/centos Simple CentOS docker image with SSH access 33

  4. 下载image 到本地
    [plain] view plain copy
    docker pull docker.io/centos

  5. 查看刚刚下载下来的image
    [plain] view plain copy
    [root@ ~]# docker images
    REPOSITORY TAG IMAGE ID CREATED SIZE
    docker.io/centos latest d123f4e55e12 2 weeks ago 196.6 MB

  6. 启动容器,放到后台,不退出,并查看启动的容器id
    [plain] view plain copy
    [root@ ~]# docker run -dt docker.io/centos /bin/bash
    abe3a1f3063de369beb91d3679f11e5f61c0fad91e418022e9b868fb2632cb33
    [root@smsgw1 ~]# docker ps -a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    abe3a1f3063d docker.io/centos “/bin/bash” 9 seconds ago Up 8 seconds cocky_wozniak

  7. 进入容器
    [plain] view plain copy
    docker exec -ti abe3a1f3063d /bin/bash

  8. 进入容器后安装JDK 8
    [plain] view plain copy
    [root@abe3a1f3063d /]# yum install java-1.8.0-openjdk.x86_64

安装完后保持为新的镜像
[plain] view plain copy
docker commit 5ed1587b3923 centos/java8
9. 安装这个是 为了运行tomcat, 刚才启动docker的时候,没有带上端口映射的参数。我们退出去再启动下
[plain] view plain copy
[root@abe3a1f3063d /]# exit

  1. 关闭并删除容器
    [plain] view plain copy
    [root@ ~]# docker ps -a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    abe3a1f3063d docker.io/centos “/bin/bash” 11 minutes ago Up 11 minutes cocky_wozniak
    [root@smsgw1 ~]# docker stop abe3a1f3063d
    abe3a1f3063d
    [root@ ~]# docker ps -a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    abe3a1f3063d docker.io/centos “/bin/bash” 12 minutes ago Exited (137) 17 seconds ago cocky_wozniak
    [root@smsgw1 ~]# docker rm abe3a1f3063d

  2. 重启启动容器
    [plain] view plain copy
    docker run -dt -p 8080:8080 -p 8990:8990 centos/java8 /bin/bash
    指定port range:
    docker run -dt -p 7000-8000:7000-8000 centos/java8 /bin/bash

挂接本地磁盘到容器 docker run -dt -p 7000-8000:7000-8000 -v /usr/local/home:/usr/local/container/home centos/java8 /bin/bash

  1. 从新进入镜像,就像在 Linux下一样,执行你想做的操作吧。
    [plain] view plain copy
    docker exec -ti 5ed1587b3923 /bin/bash

  2. copy宿主机器的文件到容器:
    docker cp /host-path/file :/containter-path
    [plain] view plain copy
    docker cp /home/msg/name.tar 5ed1587b3923:/home/software

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值