1.docker介绍
https://yeasy.gitbooks.io/docker_practice/content/
2.安装docker
https://get.daocloud.io/#install-docker-for-mac-windows
去上面网址下载对应版本docker即可
3.安装
双击打开DockerToolbox, 进行安装
安装完成后,会出现三个图标
4. 进入命令窗口
即为安装成功
5.一些常见命令
查看docker安装的镜像
docker images
查看docker正在运行的容器
docker ps
查看docker所有容器
docker ps -a
启动一个容器并进入
docker基本命令
进入容器后,ctrl+p ctrl+q 让容器在后台运行
让id对应的容器停止
docker kill 容器id
让已经停止的容器重新运行
docker start 容器id
进入正在后台运行的容器
docker attach 容器id
删除id对应的容器
docker rm 容器id
强制删除id对应的容器
docker rm -f 容器id
linux常用命令
查看目录下的文件
ls
查看目录下的文件(包含隐藏文件)
ls -a
列出当前绝对路径
pwd
创建文件夹
mkdir
创建多个文件夹
mkdir -p
6.修改docker镜像提高下载速度
docker-machine ssh default
sudo sed -i "s|EXTRA_ARGS='|EXTRA_ARGS='--registry-mirror=https://registry.docker-cn.com |g" /var/lib/boot2docker/profile
exit
docker-machine restart default
docker info
7.docker小练习
要求:
下午的任务
1. 根据ubuntu镜像创建容器为 你的名字
2. 在容器中安装python2, python3, 并设置pip镜像
3. 将容器打包为 你的名字
4. 将该镜像上传至你的仓库中 并 截图发群里
第一步:创建容器, 开启容器, 进入容器
第二步:
更新镜像
apt-get update
安装对应工具包(类似编辑器, 可以修改文件)
apt-get install -y vim
更换ubuntu镜像为阿里云
cp /etc/apt/sources.list /etc/apt/sources.list.bak(用table键补全即可)
rm /etc/apt/sources.list(删除原来的)
vim /etc/apt/sources.list(重建)
写入相关镜像
按i键
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrovimrs.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
按esc
输:wq退出
更新镜像
apt-get update
apt-get install -y wget(用于下载文件)
apt-get install -y openssh-server(用于xshell连接了服务器终端)
apt-get install -y net-tools(自带一些命令,例如ifgonfig)
apt-get install -y iputils-ping(安装ping命令,用于检测是否和某个ip连通)
apt-get install -y gcc (c++环境)
apt-get install -y make(make命令,用于编译源码)
wget:用于下载文件
openssh-server:用于xshell连接服务器终端
net-tools:自带一些命令,例如ifconfig
iputils-ping: 安装ping命令,用于检测和某个ip是否连通
gcc: c++环境
make: make命令,用于编译源码
安装python环境
apt-get install -y python3
apt-get install -y python3-pip
apt-get install -y python2.7
apt-get install -y python-pip
测试
python3
exit()
pip3 list
python2
exit()
pip2 list
用豆瓣源安装django(比较快些)或更换pip源
pip install -i https://pypi.douban.com/simple/ django
ubuntu更换pip源
1. mkdir ~/.pip
2. cd ~/.pip
3.vi pip.conf
4.写入配置
[global]
timeout = 6000
index-url = https://pypi.douban.com/simple
trusted-host = pypi.douban.com
5.保存退出
cd
pip3 install djangoexit
打包镜像
docker commit -a '作者名字' -m '描述' 容器的名字 打包的名字:版本号
登录
Docker Hub
命令查ip
ipconfig(windows)
ifconfig(linux, ubuntu)