docker的安装:
1.更新系统软件
sudo apt-get update
2.安装依赖包
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
3.添加官方密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
显示OK,表示添加成功.
执行该命令时,如遇到长时间没有响应说明网络连接不到docker网站,需要使用代-理进行
4.添加仓库
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
5.再次更新软件
sudo apt-get update
6.安装docker
sudo apt-get install docker-ce
7.查看docker版本
docker -v
显示“Docker version 18.09.0, build 4d60db4”字样,表示安装成功。
8.设置开机自启动
sudo systemctl enable docker
systemctl restart docker #重启一下
9.运行hello-world镜像
sudo docker run hello-world
会下载一个hello-world的镜像,并打印如下信息:
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
docker的基本用法
1.docker pull拉取镜像默认路径是保存在 /val/lib/docker 下
2.查看所有的镜像
sudo docker images
3.删除镜像
(1)指定名称删除镜像
sudo docker rmi 镜像名/镜像id
(2)删除所有镜像
sudo docker rmi -f $(docker images) # -f 参数表示强制删除
4.查看容器
sudo docker ps # 查看当前在运行容器
sudo docker ps -a # 查看所有容器
5.启动已经停止的容器
docker container start [containerID]
6.拷贝容器的文件到本地
例如:拷贝docker 里面的/home/abc/文件夹 到本地的home/123/ 目录下
docker cp [containerID]:/home/abc/ ~/123/
相关的问题
1.运行docker时的权限问题,在普通用户下运行docker的权限问题,如下:
执行命令:~$ docker images
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/images/json: dial unix /var/run/docker.sock: connect: permission denied
解决方法:
(1)使用超级用户权限sudo来操作:
sudo docker images
2.删除镜像出现权限问题
执行命令:sudo docker rmi hello-world
Error response from daemon: conflict: unable to delete fce289e99eb9 (must be forced) - image is being used by stopped container 2742cfb2b36a
解决方法:使用强制删除
sudo docker rmi -f hello-world
3.docker重复创建问题
docker: Error response from daemon: Conflict. The container name "/mace-dev" is already in use by container "360499f2e35471e3105adbbcaea60ede5bb07f0441652ceb1bc404be253d6105". You have to remove (or rename) that container to be able to reuse that name.
解决方法:容器已经有创建过了,可以通过移除和重命名的方法来解决。或者通过sudo docker ps -a 查看所有容器,并用docker container start [containerID] 来重启原来的容器。
参考和转载:
docker安装:https://www.cnblogs.com/tianhei/p/7802064.html
docker基础学习:
https://www.jianshu.com/p/4c88229924a1?tdsourcetag=s_pctim_aiomsg
https://www.cnblogs.com/52forjie/p/9439922.html