You know how to use Docker containers. You know how to use Docker images if they are already built. Now you want to use a Dockerfile to understand how to build images. How do you use Dockerfile and how do you create your own image?
This assumes you have installed Docker on your Linux server. If you have not, click the URL corresponding with your distribution of Linux:
1. Use vi or a text editor. Create a file called Dockerfile with the following content:
MAINTAINER NAME EMAIL
RUN apt-get -y update && apt-get -y upgrade && apt-get install -y build-essential
2. Run this command to create a Docker image:
docker build -t "foobar:contint" .
Remember to substitute foobar and contint (in the above command) according to the following bullets:
- foobar can be any arbitrary string as long as it is all lowercase. This is the name of a repository of images.
- contint is the "tag" name to idenify the image. It have uppercase and lowercase letters.
3. The Docker image has now been built. (For your information the period in the
docker build -t "foobar:contint" . command specifies the build context location.)
You are done. If you want to create a Docker container from this image just created, see this posting. When a docker build command runs, where is the image stored? For a pragmatic answer, use this command:
For a more detailed answer, see this external page.
If you want more information, see this link. For detailed reference information, see this link. See this link for best practices. To create a private registry of Docker images, see this posting. If you want to purchase a book on Docker, click here.