docker命令记录

来源:互联网 发布:超星软件打不开 编辑:程序博客网 时间:2024/06/05 14:12

01. 改变docker文件默认目录

$ vim /etc/sysconfig/docker

OPTIONS='--selinux-enabled --graph=/export/Docker'


02. run命令

docker run -idt --name test --hostname=test-p 4505:4505 -p 4506:4506 --privileged -e "container=docker" -v /sys/fs/cgroup:/sys/fs/cgroup centos:7.2.1511 /usr/sbin/init


03. 配置网络

$ vim /etc/yum.repos.d/rdo-release.repo
-------------------------------------------------------------------------------------
CentOS6.6 升级iproute
[openstack-icehouse]
name=OpenStack Icehouse Repository
baseurl=https://repos.fedorapeople.org/repos/openstack/EOL/openstack-icehouse/epel-6/
gpgcheck=0
enabled=1
-------------------------------------------------------------------------------------
yum update iproute


# At one shell, start a container and
# leave its shell idle and running


$ docker run -i -t --rm --net=none centos:6.6 /bin/bash
root@63f36fc01b5f:/#

docker run命令加上 --rm=true 选项,那当这个container执行完毕,将自动自己删除,保证了container数量不会泛滥增长


# At another shell, learn the container process ID
# and create its namespace entry in /var/run/netns/
# for the "ip netns" command we will be using below
$ sudo docker inspect -f '{{.State.Pid}}' 63f36fc01b5f
2778
$ pid=2778
$ sudo mkdir -p /var/run/netns
$ sudo ln -s /proc/$pid/ns/net /var/run/netns/$pid

# Check the bridge's IP address and netmask
$ ip addr show docker0
21: docker0: ...
inet 172.17.42.1/16 scope global docker0
...

# Create a pair of "peer" interfaces A and B,
# bind the A end to the bridge, and bring it up
$ sudo ip link add A type veth peer name B
$ sudo brctl addif docker0 A
$ sudo ip link set A up

# Place B inside the container's network namespace,
# rename to eth0, and activate it with a free 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


04. 导入容器快照

cat centos-7.2.1511-docker.tar | docker import - centos:7.2.1511

0 0