docker试题

1.
netstat -anp | grep docker     //netstat -ap | grep  registry/server
lsof -i:5000
----------------------
2.
lsof /usr/bin/docker-ccurrent
netstat -p  xxx
--------------------
3.
netstat -tlnp|grep 5000
top -p
------------
4.
docker log --tail=20  docker-registry
----------------------------------
5查看进程号                                                   long //docker inspect --format '{{.Config.Hostname}} {{.State.Status}}' container
docker inspect -f '{{.State.Pid}}' CONTAINERID         short//docker rm -f $(docker ps -a |grep Exited |awk '{print $1}')
$ pid=2778//
mkdir -p /var/run/netns
sudo ln -s /proc/$pid/ns/net /var/run/netns/$pid
ip netns
ip netns exec  $pid ip a
//													

$ ip netns  add ns
$ sudo ln -s /proc/$pid/ns/net /var/run/netns/$pid
$ ip addr show docker0
创建一对“veth pair”接口A和B,绑定A接口到网桥docker0,并启用它:

$ sudo ip link add A type veth peer name B

$ sudo brctl addif docker0 A

$ sudo ip link set A up
将B接口放到容器的网络命名空间,命名为eth0,启动它并配置一个可用IP(桥接网段)和默认网关:

$ sudo ip link set B netns $pid

$ sudo ip netns exec $pid ip link set dev B name eth0

$ sudo ip netns exec $pid ip link set eth0 up

$ sudo ip netns exec $pid ip addr add 172.17.42.99/16 dev eth0

$ sudo ip netns exec $pid ip route add default via 172.17.42.1

以上,就是Docker配置网络的具体过程。
sudo ip netns exec  [name] ip addr show   [dev-name]   permanent scope global
此外,在删除/var/run/netns/下的内容之前,用户可以使用ip netns exec命令在指定网络命名空间中进行配置,从而更新容器内的网络配置。
----------------------------------------------------------------------------------------------------------
6.
mount -t cgroup
--------------------------
7.root@devstack:/sys/fs/cgroup/memory# mkdir hello
root@devstack:/sys/fs/cgroup/memory# cd hello/
root@devstack:/sys/fs/cgroup/memory/hello# cat memory.limit_in_bytes
18446744073709551615
root@devstack:/sys/fs/cgroup/memory/hello# echo 64k > memory.limit_in_bytes
root@devstack:/sys/fs/cgroup/memory/hello# echo Pid > tasks
----------------------------------------------------------------
8.
 mkdir /sys/fs/cgroup/cpu/hello
 cd /sys/fs/cgroup/cpu/hello
ls
cat cpu.cfs_quota_us
echo 20000 > cpu.cfs_quota_us        20%     //sudo docker inspect --format "{{.Config.Volumes}}"  

cat cpu.cfs_quota_us
echo 2428 > tasks
-----------------------
9.
mkdir /sys/fs/cgroup/cpuset/XIANDAIN
echo 123  > cpuset.cpus
echo 123  > cpuset.mems
cat cpuset.cpus
cat cpuset.mems
-----------------------
10.
docker run -dit --name  1daoyun  --cpuset-cpus="0,1" ubuntu/14.04.3  /bin/bash
cat  /sys/fs/cgroup/cpuset/system.slice/docker-41a71f67d8d01a6a64a65d1109770e772738e948d4afb278418b1198fd21da47.scope/cpuset.cpus 
--------------------------------------------------
11.
mkdir /opt/xiandian/
docker run -dit  -P  --name xiandian-dir  -v /opt/xiandian ubuntu/14.04.3   /bin/bash
docker inspect -f '{{index .Volumes}}'  xiandian-dir
 docker inspect -f {{.Mounts}}   xiandian-dir          
--------------------------------------------------------
12.
mkdir /opt/xiandian/
docker run -dit --name  xiandian-dir  -v /opt/xiandian:/opt:ro ubuntu/14.04.3    /bin/bash
docker inspect -f '{{.HostConfig.Binds}}'  xiandian-dir	
-------------------------------------------------------
13.
=============
mkdir /opt/xiandian/
docker run -dit --name  xiandian-fiel  -v /opt/install.sh:/opt/install.sh ubuntu/14.04.3  /bin/bash
docker inspect -f {{.Mounts}}   xiandian-dir
=====================           
14.
//
# docker run -d -it  --name mysqldb  -P  mysql:latest  /bin/bash
# docker run -d -it  --name nginxweb  -P --link mysqldb:db  nginx:latest  /bin/bash
# docker inspect --format {{.HostConfig.Links}} 49cb289d6e73


//




docker run   --volumes-from xiandian-dir -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar  /opt/xiandian

备份

首先使用 --volumes-from 标记来创建一个加载 dbdata 容器卷的容器,并从本地主机挂载当前到容器的 /backup 目录。命令如下:
$ sudo docker run --volumes-from dbdata -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /dbdata

容器启动后,使用了 tar 命令来将 dbdata 卷备份为本地的 /backup/backup.tar。

恢复

如果要恢复数据到一个容器,首先创建一个带有数据卷的容器 dbdata2。
$ sudo docker run -v /dbdata --name dbdata2 ubuntu /bin/bash

然后创建另一个容器,挂载 dbdata2 的容器,并使用 untar 解压备份文件到挂载的容器卷中。
$ sudo docker run --volumes-from dbdata2 -v $(pwd):/backup busybox tar xvf
/backup/backup.tar

-------------------------------------------
15.

docker run -d --name mysqld    mysqld:latest
docker run -d --name nginnxweb   --link  mysqld:db  nginx;latest
docker inspect -f ...................
---------------------------------------------
16.
brctl show
---------------
17.
yum install bridge-utils
brctl addbr bridge
 ifconfig bridge 10.0.0.1 netmask 255.255.255.0 up
----------------------------------------------------------
18.
ocker run -d   -it --name mysqld    --net=none mysqld:latest
ifconfig
-----------------
19.
cd   /usr/
----------------------------------------------------
21.
mkdir  myblog && cd  myblog
vim docker-compose.yml
----------------------------------------------------------------
version: '2'
service:
	xd_db:
			image:mysql:latest
			volume:
				- db_data:/var/lib/mysql
			restart: always
			environment:
			    MYSQL_ROOT_PASSWORD:wp_xiandian
				MYSQL_DATABASE:wp_xiandian
                MYSQL_USER:wp_xiandian
                MYSQL_PASSWORD: wp_xiandian
	wordpress:
				depends_on:
					- xd_db
				image :wordpress
				volumes:
					- wp_site:/var/www/html
				ports:
					- "8080:80"
				restart: always
				environment:
					WORDPRESS_DB_HOST:db:3306
					WORDPRESS_DB_USER:wordpress
					WORDPRESS_DB_PASSWORD: wordpress
-----------------------------------------------------------------------------------------------------------
22.
docker run -d  --name cluster_server -h registry progrium/consul  -server  -bootstrap-expect 3
JOIN_IP="$(docker inspect -f '{{ .NetworkSettings.IPAddress }}' node1)”
docker run -d -p 8400:8400 --name  cluster_client1 -h server progrium/consul -join $JOIN_IP
docker run -d -p 8400:8400 --name  cluster_client2 -h client progrium/consul -join $JOIN_IP
consul members
--------------------------------------------------------------------------------------------------------------------------------
23.
consul members
------------------------------------------------------------
24.
docker pull  mariadb
docker image list
---------------------------------------
25. 
sudo docker run--name MariaDB /
-p 3307:3306 /
-v /data/db/mariadb:/var/lib/mysql /
-e MYSQL_ROOT_PASSWORD=123456 /
-e mysql  -uroot -p123456/
-e  create database xd_db;/
-e grant all privileges on xd_db.* to 'ambari'@'localhost'  identidted by '123456';/
-e grant all privileges on xd_db.* to 'ambari'@'%'  identidted by '123456';/
-d mariadb:latest
mysql    -h  -uroot -p123456
---------------------------------------------------------------------------------------------
26.
 docker export   mariadb    > mariadb_images.tar
 -------------------------------------------------------------------------------
 27.
 docker rmi mariadb 
 docker images list
 ----------------------------------
 28.
 cat mariadb_images.tar | sudo docker import    mariadb_images:latest
 -------------------------------------------------------------------------------------------------------
 29.
 docker run -d -P --name mariadb    -e MYSQL_ROOT_PASSWORD=123456     mariadb:latest
 ------------------------------------------------------------------------------------------------------------------------------------------
 30.
docker stop  mariadb   
docker ps -a
----------------------------------------------------
31.
docker start mariadb
docker ps -a
-------------------------------
32.
docker restart mariadb
docker ps -a
--------------------------------------------
33.
==============
34.35
docker inspect --format='{{.NetworkSettings.IPAddress}}' $INSTANCE_ID /// 
---------------------------------------------------------------------------------------------------------------
36.
docker inspect --format='{{.NetworkSettings.Ports}}   $INSTANCE_ID 
----------------------------------------------------------------------------------------------------------
37.



------------------------------------------------------------------------------------------
38
docker inspect -f {{.Volumes}} container-test
.docker inspect -f {{.Config.Volumes}} $INSTANCE_ID 
docker inspect volume-test1 | grep Mounts -A -20
-------------------------------------------------------------------
39.40
docker inspect $CONTAINER ID
docker inspect --format='{{json .config}}' $INSTANCE_ID
------------------------------------------------------
41.
docker ps rancher/server
------------------------------------------
42.
docker diff container
----------------------------------
43.
docker  events --until="2016-07-01"
								--since="2016-07-01"。
----------------------------------------------------------------
44.
=============
45.
docker save -o mariadb.tar  mariadb
------------------------------------------------------------------------------
46.
docker commit -a=author -m=balabala mariadb  mariadb mariadb_new:latest 
docker images list
--------------------------------
47.
docker rm -f mariadb
----------------------------------
48.49
docker ctop registry
------------------------------
50.
docker rename old  new
-------------------------------------
51.
docker network ls 
----------------------------
52.
docker network inspect bridge
----------------------------------------------
53.54
docker network create xd_net
--subnet=192.168.3.0/24 \
--gateway=192.168.3.1
------------------------------------
55.
docker run -d -P --name ubuntu --network xd_net    ubuntu:latest
docker network inspect container
docker ps -a 
docker inspect --format='{{.State.Running}}' [NAME]/[CONTAINER ID]
------------------------------------------------
56.
docker run -d -P --name ubuntu --network xd_net    ubuntu:latest
docker inspect --format='{{ .NetworkingSettings.IPAddress }}' ubuntu_latest
docker ps -a
----------------------
57.
docker network rm xd_net                                                        //docker stats  id
docker network ls
-----------------------------------------
58.
docker port  rancher/server
--------------------------------------------
59.
docker  logs  [container ID OR NAME]
---------------------------------------
60.
docker  run  ubuntu:14.04.3 /bin/echo 'hello world'
-------------------------------------------------------------------------
61.
docker  run   --rm ubuntu:14.04.3 /bin/echo 'hello world'
-------------------------------------------------------------------------------
62.
docker log --since "2017-03-01"   --until "2017.03.02 "	 containerid
-------------------------------------------------------------------------------------------
63.
docker  run   --rm ubuntu:14.04.3 /bin/echo 'hello world'
---------------------------------------------------------------------------------
64.
docker cp host_path containerID:DEST_container_path
-------------------------------------------------------------
65.
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
docker cp   /etc/yum.repos.d/local.repo     rancher/server:/opt/
docker run   -it      rancher/server    /bin/ls -r     /opt/
-----------------------------------------------------------------------------
66.
docker ps 
------------------------
67.
docker ps -a
--------------------
68 .=====================
69.
docker run -v /home/adrian/data:/data debian ls /data
docker run -it --name container-test -h CONTAINER -v /data debian /bin/bash
---------------------------------------------------------------------------------------------------------
70.
cp /etc/yum.conf /home/yum.conf
mkdir /home/centos6 -p 
# cd /home/centos6 
supermin5 -v --prepare bash coreutils -o supermin.d --packager-config /home/yum.conf
supermin5 -v --build --format chroot supermin.d -o appliance.d
 echo 7 > appliance.d/etc/yum/vars/releasever
tar --numeric-owner -cpf centos-7.tar -C appliance.d .
 cat centos-7.tar | docker import - kongxx/centos-7
--------------------------------------------------------------------------------------
71.
docker ps -a
docker rm $(docker ps -q -a)


RUN  echo '[BASE]' > /etc/yum.repos.d/base.repo
RUN  echo 'name=base' >> /etc/yum.repos.d/base.repo
RUN  echo 'baseurl=http://192.168.244.132/yum/mnt' >> /etc/yum.repos.d/base.repo
RUN  echo 'enabled=1' >> /etc/yum.repos.d/base.repo
RUN  echo 'gpgcheck=0' >> /etc/yum.repos.d/base.repo
----------------------------------------------
72.# Version: 0.0.1
FROM centos-7
MAINTAINER abc
RUN rm -f /etc/yum.repos.d/*
ADD nginx.repo /etc/yum.repos.d/nginx.repo
RUN yum  -y install   nginx
ADD nginx.conf /etc/nginx.conf
RUN systemctl enabled nginx
RUN systemctl start   nginx
EXPOSE 9090

 docker build -t  /etc/dockerfile     
 curl   
 ------------------------------------------------
 73.
 ..# Version: 0.0.1
FROM centos-7
MAINTAINER abc
RUN rm -f /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/local.repo
RUN yum -y install mariadb-server
ENV MARIADB_USER root
ENV MARIADB_PASS 1234556
ENV LC_ALL en_US.UTF-8

ADD run.sh /root/run.sh
ADD build_table.sh   /root/build_table.sh
RUN chmod u+x /root/build_table.sh
RUN /root/build_table.sh
EXPOSE 3306
ADD run.sh /root/run.sh
RUN chmod u+x /root/run.sh 
CMD  /root/run.sh 


docker build -t  dockerfile:latest       .
docker attaach       dockerfile:latest   
mysql -u root - p123456
show database;

build_table.sh
"#!/bin/bash  
mysqld_safe &  
sleep 3  
mysql -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASS' WITH GRANT OPTION;"      #授权  
mysql -e "create database scores"   #创建scores数据库     
mysql -e "create table scores.name_score(name char(20) not null,score int not null)DEFAULT CHARSET=utf8"    #创建name_score表格  
mysql -e "insert into scores.name_score values ('李明',80),('张军',90),('王小二',95)"  
run.sh
#!/bin/bash
mysql_safe

------------------------------------------------------
74.
.# Version: 0.0.1
FROM centos-7
MAINTAINER abc
WORKDIR /root
RUN rm -f /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/local.repo
RUN yum  install  -y  httpd php   php-mysql
RUN mkdir  /var/log/httpd   
 RUN mkdir  / var/www/html    

ENV MYSQL_ADDR 172.17.0.36:3306
ENV MYSQL_USER test
ENV MYSQL_PASS password
ENV LC_ALL en_US.UTF-8
ENV TERM linux  
ADD test.php  /var/www/html/test.php
EXPORT 80
ADD run.sh  
RUN chmod u+x /root/run.sh  
CMD /root/run.sh
docker build -t  dockerfile:latest       . 

run.sh
#!/bin/bash  
httpd   #启动httpd  
while true;do sleep 1000;done   #防止脚本结束  

test.php
";  
        }  
    }  
    mysql_close($con);  
?>  
----------------------------------------------------------------
75.
.# Version: 0.0.1
FROM centos-7
MAINTAINER abc
WORKDIR /root
RUN rm -f /etc/yum.repos.d/*
ADD local.repo /etc/yum.repos.d/local.repo
RUN yum  install  -y java unzip 
ADD  apache-tomcat.zip   /root
ADD index.html  /var/www/html/index.html
EXPORT  8080
 ADD catalina.sh /root/run.sh
RUN chmod u+x /root/catalina.sh 
CMD  /root/catalina.sh  
docker build -t  dockerfile:latest       . 
curl  -l  xxx.xxxx.xxx:8080
----------------------------------------------------------
76.



使用 supermin5 命令构建 centos7系统的 docker 镜像,镜像名称为 centos-7,镜像预装 yum、net-tools、initscripts 和 vi 命令,构建完成后提交镜像仓库上传操作完成后以运行该容器,查询容器的操作系统版本信息,提交查询 docker 容器列表信息、以上所有操作命令及执行结果填入答题框。
supermin5 -v --prepare bash yum  net-tools initscripts  vi coreutils -o supermin.d 
# supermin5 -v --build --format chroot supermin.d -o appliance.d
# echo 7 > appliance.d/etc/yumars/releasever
# tar --numeric-owner -cpf centos-7.tar -C appliance.d .
# cat centos-7.tar | docker import - 192.168.200.12:5000/centos-7
# docker push 192.168.200.12:5000/centos-7:latest
# docker run -i -t --rm 192.168.200.12:5000/centos-7 /bin/bash     
bash-4.2# cat /etc/redhat-release
Derived from Red Hat Enterprise Linux 7.1 (Source)
# docker images
REPOSITORY                                   TAG                 IMAGE ID            CREATED             SIZE
192.168.200.12:5000/centos-7                      latest              e40242986ac3        3 minutes ago       258.1 MB







你可能感兴趣的:(docker试题)