![]() ![]() One of the most powerful aspects of Docker is that we can layer different pre-configured images, then add our own configurations and artifacts. Docker containers come from images which are basically a blueprint for creating the container: at a minimum, an image will describe an operating system to run in the container, and it will usually also have packages and libraries installed to help an application accomplish a task. my computer if I'm developing locally, or the physical server in a public deployment. Docker containers run on a host machine which is a physical piece of hardware, e.g. I think of a container as a tiny, isolated server that is given just enough resources to run a single, specific application or a task. Stop both the API server and the Angular server ( CTL+C).īefore we set up our Docker configuration, I'd like to go over some concepts that will help clarify the steps we go through.ĭocker is a platform for creating virtual environments called containers. Now for loading the sample project if you're going to use it:Įnter fullscreen mode Exit fullscreen modeĪfter the Node and Angular servers spin up, if you navigate to you should see:Īgain, you'll see some error messages in the browser console caused by not having a database available. I'll give a brief overview of some Docker terms and concepts so that the explanations are clear, but if you're still getting started with Docker, there are far better tutorials out there. I won't be explaining any MongoDB concepts, but that's not likely to get in the way of understanding the steps below. The example repo uses Angular, Express, and Typescript, but you don't need to be familiar with any of those to follow along. However, you could also easily carry out these steps in any other project that uses Mongo - I'll just be going over the Docker setup in this article. To demonstrate, I've created a simple MEAN-stack repo and I'll show how to add scripts for containerizing the database. Lastly, a database browser tool like MongoDB Compass will be helpful for testing and inspecting the databases that we build. If you want to follow along with the sample repo, you'll also need Node.js installed. ![]() ![]() In order to test out the Docker scripts, you'll need Docker Desktop running on your local development machine. Prerequisites and loading the sample project We'll add some configuration files for a local database, then go on to seed some data, as well as simple commands to tear down and rebuild the database. In this article, I'll show you my Docker setup for container configurations and scripts to run a project's MongoDB server in a Docker container. ![]() Likewise, this setup can also simplify creating and tearing down pre-populated databases for automated tests. By leveraging volumes with Docker, we can quickly configure, change, and migrate a database, making it easier to keep database configurations consistent in higher environments. One way I've found to add some flexibility to the database layer when developing locally is using Docker to run a database server that's dedicated to the project. Indeed, one of the challenges during local development is constantly changing and reconfiguring the database as the project evolves, and safely dropping, rebuilding, and reseeding databases. One thing I've realized working off of a local MongoDB development server is all of those databases can accumulate, making it a little scary to experiment with different server configurations and deployment setups for one app. I've gotten to really enjoy working with MongoDB over the past year, and I'll usually add that in as a persistence layer when appropriate. I tend to have about a dozen or so little tech projects loaded onto my machine at any given time - little web app ideas that I work on and stop, an occasional hackathon entry, something I've built working through a tutorial, a few experiments. ![]()
0 Comments
Leave a Reply. |