如何在Linux深度系统deepin下安装docker

 

介绍

1.Linux 发展出了另一种虚拟化技术:Linux 容器(Linux Containers,缩写为 LXC)

2.Linux 容器不是模拟一个完整的操作系统,而是对进程进行隔离

3.Docker 属于 Linux 容器的一种封装,提供简单易用的容器使用接口

4.Docker 是服务器----客户端架构。命令行运行docker命令的时候,需要本机有 Docker 服务

安装docker

  apt-get install curl #如果没有就先安装curl

  curl -sSL https://get.docker.com/ | sh

  strace -p 进程id #可以看到进程的运行状态

  service docker start

将docker修改为国内镜像源
在/etc/docker/daemon.json文件中添加下面参数
此处使用的是中国科技大学的docker镜像源

  {
     "registry-mirrors" : ["https://docker.mirrors.ustc.edu.cn"]
  }

启动

  service docker restart

5.Docker 把应用程序及其依赖,打包在 image 文件里面

6.容器实例,本身也是一个文件,称为容器文件

docker image pull 名称 //拉取image文件 例:docker pull centos

docker image ls//列出所有image

docker image rm [imageName] //删除 image 文件

docker container run hello-world //运行image文件

docker container start [containID]//运行已经存在的容器

docker container kill [containID] //终止容器

docker container ls --all  //列出所有容器,包括终止的

docker container rm [containID]//删除容器

hello-world:

1.docker run hello-world

2.没有这个image会自动拉取镜像,然后运行起来

root@haima-PC:/home/haima/Desktop# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

root@haima-PC:/home/haima/Desktop# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              ccc6e87d482b        3 months ago        64.2MB
hello-world         latest              fce289e99eb9        15 months ago       1.84kB

root@haima-PC:/home/haima/Desktop# docker container ls -all
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
1b4b3169f2b5        hello-world         "/hello"            7 minutes ago       Exited (0) 7 minutes ago                       suspicious_archimedes
root@haima-PC:/home/haima/Desktop# docker container ls --all
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
1b4b3169f2b5        hello-world         "/hello"            7 minutes ago       Exited (0) 7 minutes ago                        suspicious_archimedes
6506f9a59ddf        hello-world         "/hello"            12 minutes ago      Exited (0) 12 minutes ago                       condescending_lalande
bf243aabfe11        ubuntu              "/bin/bash"         2 months ago        Exited (0) 2 months ago 

在ubuntu的docker中运行ubuntu

2.docker container exec -it 3ce8952ce68d /bin/bash //在运行的容器中执行命令,-i

在ubuntu的docker中运行centos

# 1.docker pull centos:7

# 2.
root@haima-PC:/home/haima/Desktop# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              470671670cac        3 months ago        237MB
ubuntu              latest              ccc6e87d482b        3 months ago        64.2MB
hello-world         latest              fce289e99eb9        15 months ago       1.84kB

3.给运行的容器映射本地端口

后台启动 centos

    docker container run -itd -p 6666:80 --name centos_test 470671670cac  //端口映射外面的6666到内部的80 dc86b7b90238是 IMAGE ID
      或者 
    docker container run -itd -p 6666:80 --name centos_test centos  //centos 是REPOSITORY  退出后实例不会停止
    docker ps //查看正在运行的实例
    docker exec -it centos_test /bin/sh //进入后台运行中的centos_test 或者 docker exec -it centos_test /bin/bash
    exit   //退出
    docker stop centos_test //结束后台运行中的container 用容器的名字也可以
    docker container ls -a //sj
    docker start 容器id //启动容器记录里的容器
    docker restart container-id # 重启某个容器
    docker container ls -f "status=exited" -q //列表出所有已经退出的历史实例id
    docker rm $(docker container ls -f "status=exited -q") //删除已经退出的实例历史

1)docker commit 6e54eac36507 centos_image1 //提交运行中的容器为一个镜像

2)docker run -d -it -p 6667:80 centos_image1 /bin/bash //从新run新的镜像

Docker基础 ubuntu安装docker_linux

卸载docker ce

$ sudo apt-get purge docker-ce
$ sudo rm -rf /var/lib/docker