Ubuntu16.04安装Docker 入门
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu16.04安装Docker 入门相关的知识,希望对你有一定的参考价值。
Ubuntu16.04安装Docker,基本使用入门
Ubuntu16.04安装Docker
[email protected]: ~# apt install docker.io -y
查看当前版本
[email protected]:~# docker -v
Docker version 1.9.1, build a34a1d5
[email protected]:~# 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
查找镜像
[email protected]:~# 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镜像
[email protected]: ~# 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
查看系统下的镜像
[email protected]:~# 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
创建容器并进入容器
[email protected]:~/docker# docker run -it --name website ubuntu
[email protected]:~/docker# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
82735dde0f36 ubuntu "/bin/bash" About a minute ago Up 10 seconds website
退出容器
[email protected]:/#exit
创建容器 在后台运行,指定端口
[email protected]:~/docker# docker run -d -p 2222:22 --name ubuntu ubuntu
b28bedcf41814c2597ed459704608d0f003dc8d6c5d3f9251e6641c12184874f
[email protected]:~/docker# docker rm website
docer rm -f:删除正在运行的容器
启动和关闭容器
[email protected]:~/docker# docker stop ubuntu
[email protected]:~/docker# docker start ubuntu
给容器设置root密码
[[email protected] /]# passwd root
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
设置允许root密码登录
[[email protected] /]# vi /etc/ssh/sshd_config
PermitRootLogin yes
PasswordAuthentication yes
查看IP
[[email protected] /]# 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到容器中
[email protected]:~# ssh 172.17.0.3
[email protected]‘s password:
[[email protected] ~]# 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
以上是关于Ubuntu16.04安装Docker 入门的主要内容,如果未能解决你的问题,请参考以下文章