We can download the image from the official repository from the Docker hub, and I downloaded the Ubuntu image myself, just 188M
about, very small. But looked down, the inside of the software source is still official, and is not installed vim
, so it is intended to write one Dockerfile
, use it to build a suitable for their own Ubuntu base image.
deb http://archive.ubuntu.com/ubuntu/ trusty main restricteddeb-src http://archive.ubuntu.com/ubuntu/ trusty main restricted...................
Build context
build context
, a custom folder that contains Dockerfile and some required files. For example, my:
- Dockerfile ... This is a must.
- Sources.list ... The source of the ubuntu14.04 you find in the official community
- VIMRC ... The configuration file to use when Vim is installed. My pre-configured, all are basic configuration.
.├── baseimage│ ├── Dockerfile│ ├── README.md│ ├── sources.list│ └── vimrc
Dokerfile
There are two ways of making an image:
- Create from an existing container by
commit
command
- Inconvenient operations in Dockerfile can be manipulated in the container and then submitted
- No need for bulk boot containers
- Learn and practise without needing to transplant
- Build with Dockerfile
- Convenient, flexible, portable
- Ideal for deploying a large number of mirrors and containers
Dockerfile Foundation
- ' # ' represents a comment, generally dockerfile the first line of comment container basic information and version.
- Dockerfile
命令:参数
for the basic build statement, command all uppercase, the following parameters are dependent on the command
From, must be the first command entry, which indicates which image my image is built on.
FROM ubuntu
Maintainer, followed by the construction of the name and mailbox, easy to contact
MAINTAINER adolphlwq <kenan3015@gmail.com>
LABEL, specifying the metadata for an image in the same way as a key-value pair
isasforandand install vim." Vendor="Basic image"
Add, passing files to Docker daemon at build time
ADD sources.list /etc/apt/
RUN, connect operations and commands, sudo apt-get install -y vim
etc.
ADD sources.list
CMD, build a successful image the command started by default when first started
- CMD only 1, usually by default at the end of Dockerfile
- If there is more than one cmd, only the last one works
- CMD will be
docker run ..
overwritten by the following command
CMD ["/bin/bash"]
ENV, setting environment variables
ENV REFRESHED_AT 2015-05-18
Build command
cd baseimage(构建上下文文件夹)docker build -t="duohuosrudio/ubuntu:14.04_64_base_image" .
docker build
-t
indicates the name of the container
duohuosrudio/ubuntu
Represents the duohuostudio
warehouse name (not uppercase), which ubuntu
indicates the name of the mirror.
ubuntu:14.04_64_base_image
After the 14.04_64_base_image
is the label, if not specified, the default islatest
Build process:
Errors encountered in practice
apt-get upgrade
And apt-get install vim
both to add the *-y* option, or it will be an error
- Add must be followed by two parameters,
ADD <src>... <dest>
indicating the file to be added, indicating where the file was added.
- The add file must be
构建上下文
found for the root directory and cannot exceed the scope of the build context.
If you stop building and don't worry about it, Docker caches the files in the build process, starting with the cache and saving time.
After the error is stopped, docker images
there will be only one IMAGE ID
image, this is the cache left after the build failed, we can run the image with the image ID, and then execute the debug command to check why the error! (The last 1 lines)
Adolph@geek: ~/programs/dockerworkspace/dockerfile/baseimage$ Docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZETest/ubuntu14.04_64_Base_image e9390454465c -Hours ago269.1 MBTest2/ubuntu14.04_64_Base_image e9390454465c -Hours ago269.1 MBDuohuostudio/ubuntu14.04_64_Base_image e9390454465c -Hours ago269.1 MB<none> <none> f6efc4dac25a -Hours ago269.1 MB
Summarize
-t="duohuostudio/ubuntu:14.04_64_base_image".
The last parameter of this command is used to specify the path of the Dockerfile , never forget it.
Dockerfile has been uploaded to the GitHub address
The image has also been uploaded Docker Hub
and can be downloaded via the following command
docker pull adolphlwq/ubuntu
Dockerfile: Building a base ubuntu14.04 image