查看: 5985|回复: 0

[linux] Docker容器中运行Ubuntu系统

[复制链接]

49

主题

62

帖子

3012

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3012
发表于 2019-1-19 10:26:00 | 显示全部楼层 |阅读模式

1、安装Ubuntu系统命令:

  1. docker pull ubuntu
复制代码

这是一个极度精简的系统,连最基本的wget命令都没有;所以先要apt-get update升级系统和安装apt-get install wget命令;


2、运行进入Ubuntu系统命令:

  1. docker run -ti ubuntu bash
复制代码
进入ubuntu容器:
  1. docker exec -it ubuntu bash
复制代码


3、正确退出系统方式:

先按,ctrl+p

再按,ctrl+q

绝对不能使用exit或者ctrl+d来退出,这样整个系统就退出了!!!


4、共享宿主机目录到Ubuntu系统中:

  1. docker run -it -v /AAA:/BBB ubuntu bash
复制代码

这样宿主机根目录中的AAA文件夹就映射到了容器Ubuntu中去了,两者之间能够共享;


5、登陆docker中的ubuntu镜像系统:

  1. docker run -ti ubuntu /bin/bash
复制代码

#6866 是 IMAGE ID 前四位数字-能区分出是哪个image即可


6、退出后 再进入ubuntu

1、首先用docker ps -a 查找到该CONTAINER ID对应编号(比如:0a3309a3b29e)

2、进入该系统 (此时没反应,ctrl+c就进入到ubuntu系统中去了)

  1. docker attach 0a3309a3b29e
复制代码

PS:我运行的命令

  1. docker run -it -v /download:/download -p 53:53 ubuntu bash
复制代码


附加常用命令:

一、查看ubuntu版本:

  1. cat /etc/issue
复制代码

二、修改ubuntu镜像源为ubuntu:

1、备份

  1. cp /etc/apt/sources.list /etc/apt/sources.list.backup
复制代码

2、清空内容加入以下内容

  1. vi /etc/apt/sources.list
复制代码
  1. deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
  2. deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
  3. deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
  4. deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
  5. deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
  6. deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
  7. deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
  8. deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
  9. deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
  10. deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
复制代码

3、更新生效:

  1. apt-get update
复制代码


三、安装开启ssh运行用户远程登录

1、安装sshd命令:

  1. apt-get install openssh-server openssh-client
复制代码

2、编辑/etc/ssh/sshd_config ,注释掉:PermitRootLogin without-password,增加PermitRootLogin yes


3、启动命令

  1. service ssh start
复制代码


签名
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表