Docker使用分享

来源:互联网 发布:韩国聊天软件talk 编辑:程序博客网 时间:2024/06/11 05:47

    • Docker初步
      • 0检查系统
      • 1安装docker环境
      • 2docker之Hello World
      • 3Docker基础命令
    • 通过Dockerfile构建docker镜像
      • 4编辑Dockerfile文件
      • 5构建image镜像
    • 遇到的问题
        • 1ADD 或 COPY 不能到容器中的root中
        • 2ENTRYPOINT 和 CMD 不同

Docker初步

0、检查系统

[root@5a25c7e57895 ~]# cat /etc/redhat-releaseCentOS Linux release 7.3.1611 (Core)

1、安装docker环境

 yum install -y docker
[root@5a25c7e57895 ~]# systemctl start docker.serviceFailed to get D-Bus connection: Operation not permitted[root@d96182175e58 ~]#  systemctl enable docker.serviceOperation failed: No such file or directory### 问题原因### 因为本人使用的是docker容器安装的docker### 解决方案---我没有解决了,可能还需要将CMD或者entrypoint设置为/usr/sbin/init### 启动时设置参数  --privileged### 使用该参数,Container内的root拥有真正的root权限### 否则,container内的root只是外部的一个普通用户权限。### docker run --privileged=true -it --name centosSSH  centos:7 /bin/bash### docker run --privileged -d -p 30001:12007 -p 31001:22 --name jedi-smq hfq/jedi:v6

2、docker之Hello World

#从镜像仓库中拉去hello-world镜像root@5a25c7e57895:~# docker pull hub.c.163.com/library/hello-world:latest#运行hello-world imagesroot@5a25c7e57895:~# docker run hub.c.163.com/library/hello-world#输出的内容Hello from Docker!This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 3. The Docker daemon created a new container from that image which runs the    executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it    to your terminal.To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID: https://cloud.docker.com/For more examples and ideas, visit: https://docs.docker.com/engine/userguide/root@5a25c7e57895:~# 

3、Docker基础命令

##从镜像仓库中拉去image镜像root@5a25c7e57895:~# docker pull hub.c.163.com/library/hello-world:latest##查看当前有的image镜像root@5a25c7e57895:~# docker imagesREPOSITORY                          TAG                 IMAGE ID            hello-world                         latest              48b5124b2768        8 weeks ago         1.84 kBhub.c.163.com/library/hello-world   latest              48b5124b2768        8 weeks ago         1.84 kB##启动一个镜像root@5a25c7e57895:~# docker run hub.c.163.com/library/hello-worldHello from Docker!##docker run 常用命令参数-it 交互式--name 给Container起名字-d 后台启动-p 端口-P 大写p,随机端口-v 磁盘映射eg: docker run -it -p 8080:80 -v /local/dir:/docker/container/dir ubuntu:16.04 /bin/bash##查看container状态root@5a25c7e57895:~# docker psCONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTSroot@5a25c7e57895:~# docker ps -aCONTAINER ID        IMAGE                               COMMAND                  CREATED             STATUS                      PORTS                                                        NAMES6979117aa3d8        hub.c.163.com/library/hello-world   "/hello"                 31 minutes ago      Exited (0) 31 minutes ago      ##其他###删除containerrm <container id>#删除imagedocker rmi <image id>#修改tag名称docker tag old-image[:old-tag] new-image[:new-tag] #退出后台运行:在交互式情况下执行Ctrl + PCtrl + Q#批量删除container,其中"xxx/jedi:v5"是过滤内容项docker rm $(docker ps -a | grep "xxx/jedi:v5" | awk '{print $1}')

通过Dockerfile构建docker镜像

4、编辑Dockerfile文件

FROM #基础镜像来源MAINTAINER  #作者ADD && COPY  #拷贝物理机文件到Docker容器中RUN #配置image环境的软件等ENV #配置环境变量EXPOSE #暴露端口VOLUME #挂载磁盘ENTRYPOINT && CMD #容器启动的时候执行的命令

Dockerfile样例: http://blog.csdn.net/lsziri/article/category/6785100

5、构建image镜像

## -t 表示tag .代表Dockerfile中的相对路径,绝对路径需要加 -fdocker build -t my/ubuntu:14.04 .

遇到的问题

1、ADD 或 COPY 不能到容器中的/root中

2、ENTRYPOINT 和 CMD 不同

http://www.cnblogs.com/lienhua34/p/5170335.html

0 0
原创粉丝点击