Docker安装及基本使用

Docker安装

Docker的文档做的是很好的,直接参考官方文档来进行安装:

https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-docker-ce-1

我自己使用了源的安装方式,这里简单记录一下安装步骤。

设置Dokcer源

1、sudo apt-get update

2、允许apt通过HTTPS使用存储库

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common`

3、添加Docker官方的GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

验证一下是否添加成功

sudo apt-key fingerprint 0EBFCD88

4、这里配置使用stable的源,如果想体验测试版或者开发版,在下面命令的stable后添加edge 或者 test

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

安装Docker社区版

1、sudo apt-get update

2、安裝最新版本,或者在第3步选择指定版本安装

sudo apt-get install docker-ce

3、安装指定版本

a、列出可用版本:

apt-cache madison docker-ce

b、指定版本安装

sudo apt-get install docker-ce=

4、至此Docker已经安装完成,运行以下命令验证

sudo docker run hello-world

更新Docker

如果要更新Docker,先运行sudo apt-get update,然后根据安装步骤指定版本进行安装即可。

启动Docker

sudo systemctl start docker

重启Docker

sudo systemctl daemon-reload

sudo systemctl restart docker

镜像加速

/etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件)

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

之后重新启动服务。

Docker相关网站

Docker Store

https://store.docker.com

Docker中国官方镜像

https://registry.docker-cn.com

Docker常用命令

Docker Container

  1. 启动容器:https://yeasy.gitbooks.io/docker_practice/container/run.html
  2. 后台运行:https://yeasy.gitbooks.io/docker_practice/container/daemon.html
  3. 终止容器:https://yeasy.gitbooks.io/docker_practice/container/stop.html
  4. 进入容器:https://yeasy.gitbooks.io/docker_practice/container/attach_exec.html
  5. 导出和导入容器:https://yeasy.gitbooks.io/docker_practice/container/import_export.html
  6. 删除容器:https://yeasy.gitbooks.io/docker_practice/container/rm.html

你可能感兴趣的:(Docker安装及基本使用)