synergy77
synergy77

Reputation: 29

Separating frontend app / webserver docker container

From what I've gathered the most common way to containerize an Angular app (or any frontend app) is to package up the compiled frontend app's source code and a webserver (i.e. nginx) into a single container.

If we want to scale out by adding duplicate containers, each container will have a webserver and the source code assets.

Is it possible to separate these two components into two separate containers? This way we can scale the webserver without needing each container to have a copy of the same source code assets (over and over).

I realize in most use cases this is likely not worth the effort (nor practical) to split up as I'm suggesting. I'm mostly curious from an educational perspective how or if this can be done. Also, would this be preferred if scale was huge to minimize on duplicating the same static assets in each container when the piece that needs to be scaled out is the webserver.

Upvotes: 0

Views: 545

Answers (1)

David Maze
David Maze

Reputation: 159732

If your browser application code is compiled down to static files and then built into an image, you can run as many containers based on that image as you'd like, and they won't use any extra storage. All of the containers' ephemeral filesystems will point back to the shared underlying image.

The important things to remember about a container are that it wraps a single process, and that containers' filesystems are isolated from each other. In your hypothetical setup it wouldn't make sense to have a container of compiled files since it wouldn't be running a process and other containers wouldn't be able to access those files.

If you're looking forward to clustered environments like Kubernetes, they're very good at pulling Docker images to wherever they need to be run, but it's much more complex to push "files" around. Particularly in these environments, the two approaches I've seen be successful are the one you describe here, to compile the front-end code into images, or to store and serve browser applications from a more traditional hosting environment (for static files, object storage like Amazon S3 works well) even if the backend is running in containers.

Upvotes: 2

Related Questions