docker是什么
在我的理解中docker是一个小型的虚拟机,能够定制化各种依赖.
如某台机器需要编译一个可执行文件MyTest, 其中MyTest需要用到Python内核,openssl库,编译的gcc套件.
这些都可以整合到一个docker里面,将这些离散的依赖当作一个整体管控起来
docker相当于所有依赖的快照, 有利于编译环境的迁移.
docker安装
1 | sudo apt-get remove docker docker-engine docker.io containerd runc # 卸载残余的docker |
1 | sudo apt-get update |
docker主要操作
在列举操作之前需要先明确俩概念, 一个是image 一个是container. image就是上文提到的所有依赖的快照. 而container则是运行这些快照的容器.
一个是锅一个是油盐酱醋. 只有将油盐酱醋倒到锅里才能炒出菜来.
Image Operations
Pulling an Image:
1
docker pull IMAGE_NAME[:TAG] # 把油盐酱醋从超市买回来
Listing Images:
1
docker images
Removing an Image:
1
docker rmi IMAGE_ID/IMAGE_NAME
Building an Image:
1
docker build -t IMAGE_NAME:TAG PATH/URL
Tagging an Image:
1
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
Pushing an Image to a Registry:
1
docker push IMAGE_NAME[:TAG]
Container Operations
Running a Container:
1
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Listing Running Containers:
1
docker ps
Listing All Containers (including stopped):
1
docker ps -a
Stopping a Container:
1
docker stop CONTAINER_ID/NAME
Starting a Container:
1
docker start CONTAINER_ID/NAME
Restarting a Container:
1
docker restart CONTAINER_ID/NAME
Pausing a Container:
1
docker pause CONTAINER_ID/NAME
Unpausing a Container:
1
docker unpause CONTAINER_ID/NAME
Removing a Container:
1
docker rm CONTAINER_ID/NAME
Viewing Container Logs:
1
docker logs CONTAINER_ID/NAME
Executing a Command in a Running Container:
1
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
踩坑
“Error response from daemon: Get “https://xxx.xxx.xxx.xxx/path/“: http: server gave HTTP response to HTTPS client”
此问题源于docker使用https协议而服务器那头响应的是http, 所以需要将此服务器置信.
查看docker info => Insecure Registries 我们需要在这栏中添加期望的服务器
添加配置文件重启docker1
vi /etc/docker/daemon.json
1
2
3{
"insecure-registries" : ["xxx.xxx.xxx.xxx:port"]
}1
systemctl restart docker
如果重启失败,甚至发现没有docker服务, 那就是装错了重装docker吧.😢
docker镜像站访问不了了
国内可以访问阿里云的镜像站 https://developer.aliyun.com/mirror/
复制对应Linux系统版本的镜像站地址1
mv /etc/apt/sources.list /etc/apt/sources.list.bak # 先备份一下原有的镜像站
1
vi /etc/apt/sources.list # 再把刚刚从网站上复制的镜像站地址填入配置文件,至此就替换好了镜像站了