docker基本命令使用
镜像: 就是一些文件,类似ubuntu 或者其他的一些文件
容器 : 就相当于虚拟机(电脑/盒子)
以ubuntu 镜像为列
docker pull 镜像(ubuntu) : 从网上拉取镜像到本地docker环境中
docker -itd ubuntu : 使用后台启动的方式运行镜像ubuntu 为一个 容器的方式启动
-i : 允许你对容器内的标准输入 (STDIN) 进行交互。
-t : 在新容器内指定一个伪终端或终端。
-d : 后台运行
docker ps -a :查看所有的容器(包括关闭的)
docker ps : 查看运行后台运行的容器
docker start <容器 ID> : 启动一个停止运行的容器
docker stop <容器 ID> : 停止一个正在运行的容器
docker restart <容器 ID> : 重启容器
在使用 -d 参数时,容器启动后会进入后台。此时想要进入容器,可以通过以下指令进入:
docker attach
docker exec:推荐大家使用 docker exec 命令,因为此退出容器终端,不会导致容器的停止。
docker attach 1e560fca3906 如果从这个容器退出,会导致容器的停止
docker exec -it 243c32535da7 进入容器
docker export 1e560fca3906 > ubuntu.tar 导出容器,相当于快照
cat docker/ubuntu.tar | docker import - test/ubuntu:v1 通过导出的容器进行恢复快照
docker run image:运行镜像
docker rmi image:删除镜像
docker inspect -f '{{.ID}}' store-dev :查看运行中的容器名字的长ID
docker cp 文件 id:运行中的容器下的路径(/dgg/,自己创建):拷贝文件到容器中
docker tag id spider:test 重命名镜像
cp 命令使用时 如果是windows 上到容器时,需要对路径进行专业 否则会出现如下错误
解决办法:
对windows上面的路径进行转义
docker 导出容器的环境
docker export 0a35375d4d01 >test.tar
docker 从导出的环境导入到容器中, test是导出的文件名 ubuntu:16.04 是 镜像的名字和标签
cat test.tar | docker import ubuntu:16.04
docker 中使用ubuntu16.04
安装ubuntu 镜像,并后台启动容器
在docker 中拉取镜像 docker pull ubuntu:16.04
通过docker images 查看当前拉取的镜像
使用 docker run -itd --name test ubuntu:16.04 /bin/bash 运行容器
使用docker ps 查看当前运行的容器
替换源为阿里源解决apt慢的问题
备份 copy /etc/apt/source.list /etc/apt/source.list.a 文件
本地编写sources.list文件添加阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb 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 main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
修改后 通过使用命令完成替换
docker cp 本机sources.list文件 容器ID:/etc/apt/sources.list
替换完就把ubuntu的源更换为阿里源成功了,注意这时候直接apt install 会出错 需要先执行
apt update
安装VIM
执行 apt-get install vim
这个时候直接通过vim进入编辑模式会出现error388: couldn’t find definition
先找到vim的配置文件vimrc
输入vim
然后输入:echo $VIM查询
然后即可得到查询结果图,其中图中显示的查询结果是/usr/share/vim
找到查询结果后,退出该界面,输入:quit
输入cd /usr/share/vim
接着我们修改vimrc文件,输入vim vimrc,
在该文档的最后加入:set term=builtin_ansi,然后保存退出即可
好了!现在我们再使用vim就可以方便的使用方向键了!
docker容器内设置ubuntu语言为中文
- 查看当前语言
locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
- 查看当前已安装的语言
locale -a
C
C.UTF-8
POSIX
- 安装语言包
apt-get install language-pack-zh-hans
locale-gen zh_CN.UTF-8
再次查看
locale -a
C
C.UTF-8
POSIX
zh_CN.utf8
zh_SG.utf8
- 添加到文件
echo “export LC_ALL=zh_CN.UTF-8”>> /etc/profile
source /etc/profile
如果这里添加失败,提示没有这种语言包,退出容器,再重新进入,就可以添加了
ubuntu开启ssh服务用于远程连接
激活root用户
sudo passwd root
通过
docker run -itd --name test -p 9977:22 ubuntu /bin/bash
# 安装ssh服务
apt-get install openssh-server
# 启动ssh服务
service ssh start
# 查看ssh服务是否成功开启
ps -e |grep ssh
修改ssh配置文件
vi /etc/ssh/sshd_config
修改
PermitRootLogin yes
xshell使用本机ip;端口为第二步中设置的端口(此处为9977),使用root用户及之前设置的密码即可登录
安装ftp服务
# 安装ftp服务
apt-get install vsftpd
# 启动ftp服务
service vsftpd start
# 查看ssh服务是否成功开启
ps -e | grep ftp
配置ftp文件,修改部分如下
# listen=NO
listen=YES
# 允许本地用户访问
local_enable=YES
#write_enable=YES
write_enable=YES
# 不允许匿名用户访问
anonymous_enable=NO
重启ftp服务
service vsftpd restart
使用xshell自带的xftp进行连接,ip为本机ip;端口为第二步中设置的端口(此处为9977),使用root用户及之前设置的密码即可登录