在平时开发的过程中,docker
可以用来方便地获取一个纯净的开发/部署环境,本文介绍了docker
的安装方法、最常用的几个命令以及在使用过程中定位问题的方式。
安装docker
使用阿里云源
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get -y update
sudo apt-get -y install docker-ce
apt-cache madison docker-ce
sudo apt-get -y install docker-ce=[VERSION]
添加docker
使用权限
创建docker
用户组
sudo groupadd docker
添加用户到docker
组
sudo usermod -aG docker ${USER}
重启docker
服务
sudo systemctrl restart docker
容器镜像操作
启动镜像
启动镜像+挂载一个文件+执行/bin/bash
docker run -v /data/: /data -it image-name /bin/bash
打开容器bash
sudo docker run exec -it ${docker_id} /bin/bash
容器列表
docker ps -a
本地镜像列表
docker images
拷贝文件
docker cp
从dockerfile
构建镜像
docker build -f ./path_to_dockerfile ./path_to_destination
查看容器的详细信息
docker inspect
查看容器日志
docker log
修改dockerhub
镜像
打开或创建/etc/docker/daemon.json
,写入
{
"registry-mirrors": [
"https://mirror.ccs.tencentyun.com"
]
}
完成以上步骤后,还需要重启docker
服务来完成更新。
sudo systemctl daemon-reload
sudo systemctl restart docker
查看docker 服务的运行状态
查看运行状态
systemctl status docker
ubuntu下查看docker服务的运行日志
很多时候需要定位docker
服务的失败原因,必须查看一些相关日志,这时就需要用到journalctl
,可以帮助我们定位docker
服务无法运行的一些奇怪/低级的问题。
journalctl -u docker.service
参考资料
https://docs.docker.com/install/linux/linux-postinstall/
https://cloud.tencent.com/document/product/457/9113