Ubuntu16.04安装Docker,基本使用入门
Ubuntu16.04安装Docker
root@compute2: ~# apt install docker.io -y
查看当前版本
root@compute2:~# docker -v
Docker version 1.9.1, build a34a1d5
root@compute2:~# dpkg -l | grep docker
rc docker.io 1.11.2-0ubuntu5~16.04 amd64 Linux container runtime
ii lxc-docker 1.9.1 amd64 Linux container runtime
ii lxc-docker-1.9.1 1.9.1 amd64 Linux container runtime
查找镜像
root@compute2:~# docker search ubuntu
dorapro/ubuntu ubuntu image 0 [OK]
konstruktoid/ubuntu Ubuntu base image 0 [OK]
uvatbc/ubuntu Ubuntu images with unprivileged user 0 [OK]
下载Ubuntu镜像
root@compute2: ~# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
2f0243478e1f: Pull complete
d8909ae88469: Pull complete
820f09abed29: Pull complete
01193a8f3d88: Pull complete
Digest: sha256:8e2324f2288c26e1393b63e680ee7844202391414dbd48497e9a4fd997cd3cbf
Status: Downloaded newer image for ubuntu:latest
查看系统下的镜像
root@compute2:~# docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest bd3d4369aebc 12 days ago 126.6 MB
ubuntu-1604-sleepy_kilby latest 94c88d9d0023 3 weeks ago 126.4 MB
ubuntu <none> f8d79ba03c00 3 weeks ago 126.4 MB
cmer81/centos7-openstack latest 3317e0f4e0fb 7 months ago 322.2 MB
创建容器并进入容器
root@compute2:~/docker# docker run -it --name website ubuntu
root@82735dde0f36:/#
root@compute2:~/docker# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
82735dde0f36 ubuntu "/bin/bash" About a minute ago Up 10 seconds website
退出容器
root@82735dde0f36:/#exit
创建容器 在后台运行,指定端口
root@compute2:~/docker# docker run -d -p 2222:22 --name ubuntu ubuntu
b28bedcf41814c2597ed459704608d0f003dc8d6c5d3f9251e6641c12184874f
root@compute2:~/docker# docker rm website
docer rm -f:删除正在运行的容器
启动和关闭容器
root@compute2:~/docker# docker stop ubuntu
root@compute2:~/docker# docker start ubuntu
给容器设置root密码
[root@dfbc7c3db16b /]# passwd root
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
设置允许root密码登录
[root@dfbc7c3db16b /]# vi /etc/ssh/sshd_config
PermitRootLogin yes
PasswordAuthentication yes
查看IP
[root@dfbc7c3db16b /]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.3 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:acff:fe11:3 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:11:00:03 txqueuelen 0 (Ethernet)
RX packets 442 bytes 52962 (51.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 427 bytes 44518 (43.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
SSH到容器中
root@compute2:~# ssh 172.17.0.3
root@172.17.0.3's password:
[root@dfbc7c3db16b ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.3 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:acff:fe11:3 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:11:00:03 txqueuelen 0 (Ethernet)
RX packets 434 bytes 52434 (51.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 419 bytes 42782 (41.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com