天天看點

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

[email protected]'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

本文轉自    OpenStack2015 部落格,原文連結:      http://blog.51cto.com/andyliu/1851046  如需轉載請自行聯系原作者

繼續閱讀