Nick
Nick

Reputation: 3

Do I need to share the docker image if I can just share the docker file along with the source code?

I am just starting to learn about docker. Is docker repository (like Docker Hub) useful? I see the docker image as a package of source code and environment configurations (dockerfile) for deploying my application. Well if it's just a package, why can't I just share my source code with the dockerfile (via GitHub for example)? Then the user just downloads it all and uses docker build and docker run. And there is no need to push the docker image to the repository.

Upvotes: 0

Views: 481

Answers (2)

David Maze
David Maze

Reputation: 159722

There are two good reasons to prefer pushing an image somewhere:

  1. As a downstream user, you can just docker run an image from a repository, without additional steps of checking it out or building it.
  2. If you're using a compiled language (C, Java, Go, Rust, Haskell, ...) then the image will just contain the compiled artifacts and not the source code.

Think of this like any other software: for most open-source things you can download its source from the Internet and compile it yourself, or you can apt-get install or brew install a built package using a package manager.

By the same analogy, many open-source things are distributed primarily as source code, and people who aren't the primary developer package and redistribute binaries. In this context, that's the same as adding a Dockerfile to the root of your application's GitHub repository, but not publishing an image yourself. If you don't want to set up a Docker Hub account or CI automation to push built images, but still want to have your source code and instructions to build the image be public, that's a reasonable decision.

Upvotes: 1

Irfan wani
Irfan wani

Reputation: 5094

That is how it works. You need to put the configuration files in your code, i.e, Dockerfile and docker-compose.yml.

Upvotes: 0

Related Questions