Ubuntu16.04安装Docker 入门
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
本文出自 “技术成就梦想” 博客,请务必保留此出处http://andyliu.blog.51cto.com/518879/1851046