背景
-----最近换了电脑想编译android源码,需要个linux环境,虚拟机不想搞,感觉太笨重了,据android 官网说建议用unbuntu系列的,于是就有了此文
安装环境
Macos
安装docker
1.使用命令安装
brew cask install docker
为什么不是brew install而是brew cask install 呢?
brew install 的步骤是./configure && make && make install
brew cask install 是下载解压已经编译好的.pkg/.dmg下载目录是:/opt/homebrew-cask/Caskrooms或者/usr/local/Caskroom 不同版本可能有差异
$ brew cask install docker
==> Creating Caskroom at /usr/local/Caskroom
==> We'll set permissions properly so we won't need sudo in the future
Password: # 输入 macOS 密码
==> Satisfying dependencies
==> Downloading https://download.docker.com/mac/stable/21090/Docker.dmg
######################################################################## 100.0%
==> Verifying checksum for Cask docker
==> Installing Cask docker
==> Moving App 'Docker.app' to '/Applications/Docker.app'.
🍺 docker was successfully installed!
- 显示docker app,next,最后状态栏显示小鲸鱼图标表示安装完成了!
2.官网安装
这里有官方的安装方式,以及系统要求,跟我在这里的安装方式其实没有区别。😂
- 点击红框Download from Docker Hub 是这个页面
- 选择Description项找到Installation
这里右手边有个Get Docker(这个也是下载),不用点
因为我不知道她是什么版本Stable还是Edge
Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE。
社区版按照stable和edge两种方式发布,每个季度更新stable版本,如17.06,17.09;每个月份更新edge版本,如17.09,17.10。
-
两蓝色药丸你挑一个,stable是季更新,edge是月更新,statble相对稳定
-
正常操作安装就行,需要输入系统密码给一docker 权限啊什么的,这里不再展开
-
当状态栏出现
小鲸鱼
说明已经运行起来了 -
-
然后你去可以点击 红框处创建Docker Id,注册。登录
可能遇到的问题:
- 下面这位博主说从官网可能下不下来,反正我没遇到过,我碰巧看到的
小奥蕉Docker for Mac安装与入门
使用步骤
基础操作
docker version
如下说明安装成功
$ docker version
[Client: Docker Engine - Community
Version: 19.03.8
API version: 1.40
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:21:11 2020
OS/Arch: darwin/amd64
Experimental: false
Server: Docker Engine - Community
.......
docker image ls
查看所有镜像(这里的hello-world 是docker提供的
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 3 months ago 13.3kB
docker run hello-world
如下说明docker 可以正常工作了
$ docker run 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/
回顾主题,拉取Ubuntu 镜像
1.docker pull ubuntu
拉取ubuntu镜像
$ docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
d51af753c3d3: Pull complete
fc878cd0a91c: Pull complete
6154df8ff988: Pull complete
fee5db0ff82f: Pull complete
Digest: sha256:747d2dbbaaee995098c9792d99bd333c6783ce56150d1b11e333bbceed5c54d7
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
docker image ls
查看镜像
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 1d622ef86b13 5 days ago 73.9MB
sudo docker run -it --name 容器名称 -v 需要挂载的主机的目录:容器的目录 镜像名称 /bin/bash
创建并启动容器
$ sudo docker run -it --name firstUbuntu -v /Users/pz/mac/dockerProject/firstUbuntu:/soft ubuntu /bin/bash
Password:
root@2e31c3cdc8cc:/#
cd /soft/
进入挂载到主机的目录touch abc.txt
创建abc.txt
root@2e31c3cdc8cc:/# cd /soft/
root@2e31c3cdc8cc:/soft# ls
root@2e31c3cdc8cc:/soft# touch abc.txt
root@2e31c3cdc8cc:/soft# ls
abc.txt
root@2e31c3cdc8cc:/soft#
-
查看主机目录下是否有
abc.txt
-
在容器中
exit
退出容器 -
在主机中
docker stop firstUbuntu
停止容器(firstUbuntu 容器名称 -
docker container ls -all
查看当前的容器列表
$ docker container ls -all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2e31c3cdc8cc ubuntu "/bin/bash" 7 minutes ago Exited (0) About a minute ago firstUbuntu
docker start firstUbuntu
启动容器docker exec -it firstUbuntu /bin/bash
进入容器
可能遇到的问题:
1.docker run hello-world
如下:运行失败,一看就是http响应失败,说明访问不了docker镜像库,
当然,国内默认就是访问不了的,就算你拉取镜像也是需要配置如下
docker: Error response from daemon: Get https://registry-1.docker.io/v2/:net/http:
request canceled while waiting for connection (Client. Timeout exceeded while
awaiting headers)
See ' docker run --help'.
解决:
- 1 设置registry-mirrors 即可
1.2 添加或替换如下json就行,这里我也忘记从哪偷来的 阿里云了,能用就行。
"registry-mirrors": [
"https://6kx4zyno.mirror.aliyuncs.com"
]
1.3 点击绿色摁钮Apply & Restart
即可
参考
https://www.runoob.com/docker/macos-docker-install.html
https://www.cnblogs.com/Peter2014/p/7704306.html