0

I'm a beginner with Docker and I'm trying to get to grips with its structures and processes. I have the following scenario at work that I'm trying to figure out.

I have a docker container my-container running on a node. Inside this container is a Dockerfile, which I've updated with a couple of RUN lines so that it will install something every time the container is run. I removed the existing docker image, and I want to rebuild and tag a docker image using the updated Dockerfile. The Dockerfile edit and image rebuild is only required once.

Is there a best, or generally accepted method of getting docker build to run using a Dockerfile that is located within a container? I've searched around and could find a few different methods:

  • Run docker build from within the container, using Docker in Docker as outlined here
  • Run docker build from within the container by passing the socket (although this should never be done, is there a way of closing the vulnerability after you've run the command (a once off) and running the container again without the bind mounting using -v?
  • Run docker build from outside the container, but using the url of the container that contains the updated dockerfile as the build context? See: 3 different ways to provide docker build context and Docker docs.
  • Some other method that I haven't managed to find yet.
  • Thanks

    Ruairios
    • 328
    • 1
    • 9

    2 Answers2

    0

    There is a Docker image called "Docker in Docker" which lets you call Docker inside the container, maybe that could point some hints in your setup.

    https://hub.docker.com/_/docker/

    juancho
    • 79
    • 6
    • Thanks for your answer and suggestion - Docker in Docker is one of the methods I'm considering, but it seems to be open to a lot of potential problems. – Ruairios Apr 19 '18 at 11:46
    0

    you can define the Dockerfile inside the container as volume and then call that Dockerfile from outside(host) with docker build command. i think its the easiest way.

    nephilim_boy
    • 46
    • 1
    • 4