Creating a Docker Base Image from a Docker File?

I have a working docker image running my application, but I have a problem that whenever I add new dependencies, I have to reinstall all my dependencies. This sucks. I know that I can get around this by installing dependencies on separate lines, but they are clumsy and not portable if I want to build from different places. I would prefer to make a basic image with the requirements that I know I need now (especially those that take a lot of time to install), and then just compile all the new images so that I have a quick build time from any machine. So, does all this suggest a good way to create a base image from a Docker file, or is there a better way to accomplish portability and the fast build time I'm looking for?

+4
source share
1 answer

Any docker image is a base image. You can use from tagto use any image that you created or pulled from the repository as a base image.

Work is being done ( Docker issue332 ) to be able to smooth out basic images for faster loading, but it has not yet been completed. Until you define any ports and volumes in the base image, you can use the hack suggested by Solomon in the comments on this issue, i.e.

"" , tarball . , , , , env, , .. --Solomon Hykes

:

# Run a NOOP command that creates a container
container_id=$(docker run -d <BASE-CONTAINER> ls)

# Run export the image as a tarball
docker export $container_id > image.tar

# Import the image into a new container
cat image.tar | docker import - yourname/BASE:TAG

# Now you can use ```from yourname/BASE:TAG``` in your docker files.
# Or you can push to dockerhub with the following 
# commands so you can use on other machines
docker login
docker push yourname/BASE:TAG
+2

All Articles