Docker安装与使用

前言

  Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。

安装

  • 卸载旧版本的docker
    • sudo apt-get remove docker docker-engine docker-ce docker.io
  • 更新
    • sudo apt-get update
  • 安装以下包以使apt可以通过HTTPS使用存储库(repository)
    • sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
  • 添加Docker官方的GPG密钥
    • curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  • 安装stable
    • sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  • 安装版本的docker
    • sudo apt-get install -y docker-ce

列出可用的docker镜像

  • apt-cache madison docker-ce
  • 安装:
    • sudo apt-get install docker-ce=<VERSION>
  • 这里写图片描述

状态

  • 查看docker当前状态
    • service docker status
    • 这里写图片描述
  • 重新启动服务
    • 强制重启:service docker force-reload
    • 重启:service docker restart
  • 启动:
    • service docker start
  • 停止:
    • service docker stop

安装失败

Traceback (most recent call last):
  File "/usr/bin/docker-compose", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/home/wangyu/Python/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3138, in <module>
    @_call_aside
  File "/home/wangyu/Python/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3122, in _call_aside
    f(*args, **kwargs)
  File "/home/wangyu/Python/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3151, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/home/wangyu/Python/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 664, in _build_master
    ws.require(__requires__)
  File "/home/wangyu/Python/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 981, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/home/wangyu/Python/anaconda3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 867, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'docker-compose==1.8.0' distribution was not found and is required by the applicatio

  版本不大对╮(╯▽╰)╭,重新安装下:

  • pip install docker-compose==1.8.0 --user
compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for PyYAML
  Running setup.py clean for PyYAML
Failed to build PyYAML

  好吧,又少了一个库。

  • sudo apt-get build-dep python-lxml
  • sudo pip install lxml --upgrade

      安装完毕之后重新。

  • pip install docker-compose==1.8.0 --user

      搞定O(∩_∩)O
      
    这里写图片描述

使用教程

docker文档:点击跳转

  • 启动docker服务
    • Ubuntu:service docker start
    • Centos:systemctl start docker
  • 关闭docker服务
    • Ubuntu:service docker stop
    • Centos:systemctl start docker
  • 启动一个Container
    • sudo docker start 名称
    • sudo docker attach 名称,进入一个启动后的Container,但是一旦Ctrl+D退出后,Container也终止了。
    • sudo docker exec -it recui /bin/bash,进去一个启动后的Container,可以使用Ctrl+D退出Terminal,但是Container可以在后台运行。
      • recui:镜像名称
      • -t:flag assigns a pseudo-tty or terminal inside the new container.
      • -i:flag allows you to make an interactive connection by grabbing the standard in (STDIN) of the container.
      • /bin/bash:启动一个命令行窗口。
  • 查看运行的docker:docker ps

附录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值