环境是virtualbox中安装了Ubuntu 16,目的在Ubuntu环境下安装使用docker。步骤来源为http://www.docker.org.cn/book/docker/what-is-docker-16.html。
#sudo apt-get install docker-io
#docker version
Client:
Version:1.12.6
API version:1.24
Go version:go1.6.2
Git commit:78d1802
Built: TueJan 31 23:35:14 2017
OS/Arch:linux/amd64
#sudo docker search tutorial
NAME DESCRIPTION
learn/tutorial This is the backend of react comment
#docker pull learn/tutorial
Using default tag: latest
Latest: Pulling from learn/tutorial
271134aeb542: pull complete
Digest: xxxxxxxxxxxxx
Stutas: Downloaded newer image forlearn/tutorial:lastest
#sudo docker run learn/tutorial echo “hello world”
补充:在docker容器中运行bash
#sudo docker run –t –I learn/tutorial
Ok
#docker run learn/tutorial apt-get –y install
报错:
Docker: Cannot connect to the Docker daemon. Is thedocker daemon running on this host?
原因:权限问题,从0.5.2开始docker的守护进程总是以root用户来运行,从0.5.3开始docker创建一个名为docker组,然后将用户加入这个组内。
解决方案
1.使用root权限运行
#sudo docker run learn/tutorial apt-get –y installping
或者
#su
#systemctl restart docker
#docker run learn/tutorial apt-get –y install ping
2.将当前用户加到docker用户组中
#gpasswd liudongwei docker
查看运行的容器
# docker ps –l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
C24e7d6b72aa learn/tutorial “apt-get –yinstall p” 11 seconds ago Exited(0) 2 second ago zen_bratin
# docker commit C24e7d6b72aa learn/ping
Sha256:227bb5dc805a33f1eac6f8ae4557bdb763dd2f0671a72fa95c3a87186c91eec
# docker run learn/ping ping www.baidu.com
Ok
# sudo docker inspect
得到json字符串
#sudo docker push learn/ping