1、使用交互式方式运行容器,可以和容器进行对话
[dkuser@c741 ~]$ docker run -i -t ubuntu:15.10 /bin/bash
这时候就已经进入容器内部了。
参数说明:
-t:在新容器内指定一个伪终端或终端。
-i:允许你对容器内的标准输入 (STDIN) 进行交互。
2、更新出错解决
root@4e09338995bd:/# apt-get update
Ign http://archive.ubuntu.com wily InRelease
Ign http://archive.ubuntu.com wily-updates InRelease
Ign http://archive.ubuntu.com wily-security InRelease
Ign http://archive.ubuntu.com wily Release.gpg
Ign http://archive.ubuntu.com wily-updates Release.gpg
Ign http://archive.ubuntu.com wily-security Release.gpg
Ign http://archive.ubuntu.com wily Release
Ign http://archive.ubuntu.com wily-updates Release
Ign http://archive.ubuntu.com wily-security Release
Err http://archive.ubuntu.com wily/main Sources
404 Not Found [IP: 91.189.88.162 80]
Err http://archive.ubuntu.com wily/restricted Sources
404 Not Found [IP: 91.189.88.162 80]
......
解决:
容器源配置
root@4e09338995bd:/# cp /etc/apt/sources.list /etc/apt/sources.list.bak
root@4e09338995bd:/# sed -i -r 's/([a-z]{2}\.)?archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
root@4e09338995bd:/# sed -i -r 's/security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
更新成功
root@4e09338995bd:/# apt-get update
Hit http://old-releases.ubuntu.com wily InRelease
Hit http://old-releases.ubuntu.com wily-updates InRelease
Hit http://old-releases.ubuntu.com wily-security InRelease
Get:1 http://old-releases.ubuntu.com wily/main Sources [1411 kB]
.....
Get:18 http://old-releases.ubuntu.com wily-security/universe amd64 Packages [70.7 kB]
Fetched 16.4 MB in 1min 17s (211 kB/s)
Reading package lists... Done
3、安装工具
因为不能使用ifconfig和ping等命令,所以安装基础包。
如果不知道命令是那个包的可以使用下面命令查看
root@4e09338995bd:/# apt-file search bin/ifconfig
root@4e09338995bd:/# apt install net-tools
root@4e09338995bd:/# apt install iputils-ping
root@4e09338995bd:/# apt-get install network-manager
4、查看容器主机网络等信息
root@4e09338995bd:/# ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:02
inet addr:172.17.0.2 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6867 errors:0 dropped:0 overruns:0 frame:0
TX packets:6720 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:25486263 (25.4 MB) TX bytes:387001 (387.0 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
查看dns地址
root@c741:/# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 8.8.8.8
nameserver 114.114.114.114
5、生成新的镜像
exit 退出容器
查看生成的容器
[dkuser@c741 ~]$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4e09338995bd ubuntu:15.10 "/bin/bash" 2 hours ago Exited (130) 32 minutes ago hopeful_roentgen
把容器生成新的镜像
[dkuser@c741 ~]$ docker commit -m "ubuntu:15.10_with_basis_env" -a "sxzhou" 4e09338995bd ubuntu:15.10_basis_env
参数说明:
-m:说明信息
-a:创建者
查看生成的镜像
[dkuser@c741 ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 15.10_basis_env 6422827a9898 23 seconds ago 492MB
ubuntu 15.10 9b9cb95443b5 2 years ago 137MB
参考: