By accessing the website and accepting the Cookie Policy, you agree to use the cookies provided by the Site in accordance with to analyze traffic, remember your preferences, and optimize your experience.

标签 - Docker

Docker    2018-11-23 17:07:33    678    0    0
apt-get install apt-transport-https dirmngr

添加 Docker 的库到 Debian 9 的 /etc/apt/sources.list

echo 'deb https://apt.dockerproject.org/repo debian-stretch main' >> /etc/apt/sources.list

可以用 cat 命令看一下

Docker    2018-11-23 17:07:33    140    0    0
  1. Run this command to download the latest version of Docker Compose:

    sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local
Docker    2018-11-23 17:07:33    195    0    0

一、基本概念

1. 什么是Docker

...

2. Docker的基本概念

  • 镜像(Image)

是一个只读模板,用来运行Docker容器。

  • 容器(Container)

负责应用程序的运行,包括操作系统、用户添加的文件以及元数据
容器是从镜像创建的运行实例。它可以被启动、开始、停止、删除。每个容器都是相互隔离的、保证安全的平台。

注:镜像是只读的,容器在启动的时候创建一层可写层作为最上层。

  • 仓库(Repository)

仓库是集中存放镜像文件的场所。
仓库分为公开仓库(Public)和私有仓库(Private)两种形式。

注:Docker 仓库的概念跟 Git 类似,注册服务器可以理解为 GitHub 这样的托管服务

二、快速开始

1. 安装

# ubuntu
curl -fsSL https://get.docker.com/ | sh
sudo service docker restart

2. 镜像

获取

# 从仓库注册服务器拉取
sudo docker pull ubuntu:14.04  # 官方仓库注册服务器,相当于 sudo docker pull registry.hub.docker.com/ubuntu:14.04
# 也可使用其他仓库,如: sudo docker pull dl.dockerpool.com:5000/ubuntu:12.04

显示

sudo docker images

运行

sudo docker run -t -i ubuntu:14.04 /bin/bash

修改

# 运行容器bash,通过shell进行操作
sudo docker run -t -i ubuntu:14.04 /bin/bash

# 提交更新
sudo docker commit -m "Added json gem" -a "Docker Newbee" 0b2616b0e5a8 ouruser/sinatra:v2
  • -m: 提交信息
  • -a: 指定更新的用户信息
  • 0b2616b0e5a8: 容器的 ID
  • ouruser/sinatra: 仓库名
  • v2: 仓库tag

创建

  1. 通过修改已有image, 具体操作修改中已有

  2. 通过Dockerfile来创建

mkdir mydockerimg

# docker image的配置文件
vim Dockerfile

# 创建image
sudo docker build
Docker    2018-11-23 17:07:33    228    0    0

这些命令总是记不住,或者说不用心去记,所以记录在本文中,以便将来查询。

列出所有的容器 ID

docker ps -aq

停止所有的容器

docker stop $(docker ps -aq)

删除所有的容器


docker rm $(docker ps -aq) ​

删除所有的镜像

docker rmi $(docker images -q)

复制文件