docker镜像创建
1. 首选要创建一个Dockerfile文件,内容如下:
FROM alpine:latest
MAINTAINER lobin <lobin.hotmail.com>
RUN apk add --no-cache --update-cache bash
CMD ["/bin/bash"]
2. 生成镜像,取名apline-bash
[root@VM_0_13_centos demo]# docker build -t apline-bash .
Sending build context to Docker daemon 2.048 kB
Step 1/4 : FROM alpine:latest
---> 3fd9065eaf02
Step 2/4 : MAINTAINER lobin <lobin.hotmail.com>
---> [Warning] IPv4 forwarding is disabled. Networking will not work.
---> Running in a73f8500b494
---> 398e9ed5537e
Removing intermediate container a73f8500b494
Step 3/4 : RUN apk add --no-cache --update-cache bash
---> [Warning] IPv4 forwarding is disabled. Networking will not work.
---> Running in dd629be23601
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.7/main: temporary error (try again later)
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz: temporary error (try again later)
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.7/community: temporary error (try again later)
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
bash (missing):
required by: world[bash]
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz: temporary error (try again later)
ERROR: unsatisfiable constraints:
The command '/bin/sh -c apk add --no-cache --update-cache bash' returned a non-zero code: 1
3. 出现以上错误,没辙,重启docker能解决,但问题不知道
[root@VM_0_13_centos demo]# systemctl restart docker
4. 重新构建镜像
[root@VM_0_13_centos demo]# docker build -t apline-bash .
Sending build context to Docker daemon 2.048 kB
Step 1/4 : FROM alpine:latest
---> 3fd9065eaf02
Step 2/4 : MAINTAINER lobin <lobin.hotmail.com>
---> Using cache
---> 398e9ed5537e
Step 3/4 : RUN apk add --no-cache --update-cache bash
---> Running in 4ce990201bfd
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
(1/6) Installing pkgconf (1.3.10-r0)
(2/6) Installing ncurses-terminfo-base (6.0_p20171125-r0)
(3/6) Installing ncurses-terminfo (6.0_p20171125-r0)
(4/6) Installing ncurses-libs (6.0_p20171125-r0)
(5/6) Installing readline (7.0.003-r0)
(6/6) Installing bash (4.4.19-r1)
Executing bash-4.4.19-r1.post-install
Executing busybox-1.27.2-r7.trigger
OK: 13 MiB in 17 packages
---> b6ed2497fc7e
Removing intermediate container 4ce990201bfd
Step 4/4 : CMD /bin/bash
---> Running in 61323661705d
---> a7414979d240
Removing intermediate container 61323661705d
Successfully built a7414979d240
[root@VM_0_13_centos demo]#
Message from syslogd@localhost at Jul 4 23:49:17 ...
kernel:unregister_netdevice: waiting for lo to become free. Usage count = 1
Message from syslogd@localhost at Jul 4 23:49:27 ...
kernel:unregister_netdevice: waiting for lo to become free. Usage count = 1
5. 查看镜像,好小呀
[root@VM_0_13_centos demo]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
apline-bash latest a7414979d240 8 minutes ago 9.5 MB
docker.io/redis latest 71a81cb279e3 7 days ago 83.4 MB
docker.io/mysql latest 8d99edb9fd40 7 days ago 445 MB
docker.io/alpine latest 3fd9065eaf02 5 months ago 4.15 MB