Docker 安装配置

安装:

yum install -y docker-io

 

启动:

/etc/init.d/docker start

 

诊断模式手动启动:

[root@node110 ~]# /usr/bin/docker -d

WARN[0000] You are running linux kernel version2.6.32-573.el6.x86_64, which might be unstable running docker. Please upgradeyour kernel to 3.10.0.

INFO[0000] Listening for HTTP on unix(/var/run/docker.sock)

INFO[0000] [graphdriver] using prior storage driver"devicemapper"

WARN[0000] Running modprobe bridge nf_nat failed withmessage: install /bin/true

install /sbin/modprobe --ignore-install bridge&& /sbin/sysctl -q -w net.bridge.bridge-nf-call-arptables=0net.bridge.bridge-nf-call-iptables=0 net.bridge.bridge-nf-call-ip6tables=0

install /bin/true

insmod/lib/modules/2.6.32-573.el6.x86_64/kernel/net/bridge/bridge.ko

, error: exit status 1

FATA[0000] Error starting daemon: Error initializingnetwork controller: Error creating default "bridge" network: packagenot installed

 

 

 

搜索centos的镜像:

[root@node121 ~]# docker search centos

NAME                                  DESCRIPTION                                     STARS     OFFICIAL  AUTOMATED

centos                                 The officialbuild of CentOS.                  2960      [OK]      

jdeathe/centos-ssh                     CentOS-6 6.8 x86_64 /CentOS-7 7.3.1611 x8...   52                   [OK]

nimmis/java-centos                     This is docker images of CentOS 7 withdif...   20                   [OK]

million12/centos-supervisor            Base CentOS-7 with supervisordlauncher, h...   12    

 

官方的mirrors

个人的mirrors

 

下载centos的docker镜像:

[root@node121 ~]# docker pull centos

latest: Pulling from centos

3690474eb5b4: Pull complete

0a444b299d5a: Pull complete

a04895de1996: Pull complete

d4350798c2ee: Pull complete

Digest:sha256:6e45de12a92ce6fcc0e3d0ffca8000833675f96679b3f1ecf71485c339826f27

Status: Downloaded newer image for centos:latest

 

查看当前系统存在的镜像:

[root@node121 ~]# docker images

REPOSITORY         TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

centos             latest             d4350798c2ee        2 weeksago         191.8 MB

 

 

删除容器:

#docker rm

#docker rm  -f   id值

 

 

启动容器:

[root@node121 ~]# docker run centos /bin/echo 'HelloWorld'    #这个Hello world命令的输出是由centos输出的而不是当前系统输出的

Hello World

 #系统docker系统的状态

[root@node121 ~]# docker ps -a

CONTAINER ID       IMAGE               COMMAND                CREATED             STATUS                     PORTS               NAMES

699f2ebc6a86       centos             "/bin/echo 'Hello Wo   7seconds ago       Exited (0) 5 secondsago                       jolly_franklin

 

进入容器中(另一个docker运行的操作系统):

#docker run --name mydocker  -it centos /bin/bash

 

用centos的镜像创建一个容器,并在这个容器中运行centos操作系统

 

查看容器的IP地址:

[root@462442d61745 /]# cat /etc/hosts

172.17.0.2          462442d61745

127.0.0.1           localhost

::1         localhostip6-localhost ip6-loopback

fe00::0   ip6-localnet

ff00::0   ip6-mcastprefix

ff02::1   ip6-allnodes

ff02::2   ip6-allrouters

 

docker会运行指定的应用进程,如果应用程序退出,则docker也退出了

 

退出docker容器:

#exit

 

退出后查看docker的运行状态:

[root@node121 ~]# docker ps -a

CONTAINER ID       IMAGE               COMMAND                CREATED             STATUS                      PORTS               NAMES

462442d61745       centos              "/bin/bash"            10 minutes ago      Exited (0) 8 seconds ago                        mydocker           

699f2ebc6a86       centos              "/bin/echo 'Hello Wo   12 minutes ago      Exited (0) 12 minutes ago                       jolly_franklin 

 

[root@node121 ~]# docker ps -l

CONTAINER ID       IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES

5df8eb0d89ad       nginx               "nginx -g'daemon of   11 minutes ago      Up 8 minutes        80/tcp, 443/tcp     mynginx

 

 

重新启动一下已退出的容器:

[root@node121 ~]# docker start 462442d61745

462442d61745

 

 

启动一个容器并在后台运行;

^C[root@node121 ~]# docker run -d --name mydocker1centos

bacfcede0569a7f748755b5f8fc978dd7d16b764ef522937ea958c38d0d2e460

 

 

#docker ps -a

 

 

 

停止一个已运行的容器:

#docker stop c0b0e3sdfeefwf

 

 

进入一个已运行的容器里:

方法一:

#docker attach id

 

#docker -ps -l

 

方法二:

获取一个容器的PID

#docker inspect --format"{{.State.Pid}}"  mynginx

32439

 

yum install util-linux

#nsenter --target 32439 --mount --uts --ipc --net --pid           #进入容器的另一种方法

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS