2

I want to create an image A in one instance/server, but in that instance there is no internet connection.

So can I create an image B with all packages installed at my machine and then Push to x.x.x.x and use it in image A as the FROM tag?

It will look like :

FROM x.x.x.x/B:latest
RUN ***
ENTRYPOINT

Please suggest a correct solution for this problem.

3
  • 2
    Yes. You can do it. You can keep your image locally or push it to docker hub. Commented Jan 9, 2019 at 12:01
  • If you want something scalable, you can try to select a machine and make it a docker registry ( server side application that stores and lets you distribute Docker images): : $ docker run -d -p 5000:5000 --restart=always --name registry registry:2 Commented Jan 9, 2019 at 12:08
  • I am running from YAML file. Commented Jan 12, 2019 at 12:04

2 Answers 2

3

Yes, you can.

First though, you say image A is on a server that has no internet connection. If that is true, then you can't access the built image B that you've pushed to x.x.x.x unless the x.x.x.x that you refer to is localhost.

To answer the question fully with the assumption that there's no internet:

Dockerfile B contains all the stuff you want in your base image. Build that. Then move the image to the internet-less server that you're building image A on. (To move the image, check out docker export or docker save commands and/or google 'moving a docker image from one host to another'. My initial search lead me here: https://blog.giantswarm.io/moving-docker-container-images-around/)

(note: for anyone that wants to do this and you have a internet connection, you would push image B to a repo and then pull the image straight from there in Dockerfile A which would skip the moving from host to host part.)

Then, just like you've written already, the Dockerfile for image A should have:

FROM imageB:latest

to pull from your first image. It's all pretty easy. Long story long, yes, you can build your own images and then build other images based off of that image.

Sign up to request clarification or add additional context in comments.

Comments

2

Short answer - of course, you can. You can use any image, including your own, to build new images.

Long answer - consider Docker multistage build for you purpose. This allows reduce the amount of images and the space occupied by your docker registry.

You can read more on https://docs.docker.com/develop/develop-images/multistage-build/

In short - you create a single Dockerfile where you define several images, based on each other. In case you don't need your base image outside from derived, this is your case. Following example will illustrate:

Dockerfile

# First create base image
FROM foo:latest as mybase # note we tag it 'mybase' 
RUN blahblah

FROM mybase  # here we derive new image, note Dockerfile is same!
RUN blahblahblah

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.