This brief article is designed to highlight knowledge gaps in most web develop coding bootcamp programs with a particular focus on app deployment related skills and practices. People who are in a bootcamp or have recently graduated from a bootcamp will benefit most from this article.
Usually coding bootcamps conclude with students creating applications that showcase their programmatic skills and then releasing their apps by connecting the source repository with a deployment service like Heroku or GitHub Pages. Although these deployment services can be a fast and easy solution for an individual or a small project, these services are generally not used by actual companies or organizations, especially not at the enterprise level. Instead, most companies and organizations use Docker to “containerize” their apps and cloud services to “ship” them.
Meet the Whale in Container Services
Docker is a software service/platform that allows us to put our app into a container, a sort of standardized unit of software, which guarantees that our app will run consistently in every environment. An environment in this case is a unique space for developing and testing new code, for example, a common set up of environments is Development, Quality Assurance (QA), Staging, and Production 💲. Fans of Docker appreciate how its containerized applications behave similarly regardless of what environment they are hosted in.
Using Docker in a practical sense involves building and running Docker images and containers for your web app. Begin by creating a Dockerfile in your app directory; this file will hold all the necessary dependencies to run your application. With a run command, you can create a Docker image from your Dockerfile and on top of the image you can run a container; this container usually is the final product that is delivered to the end-user who uses your app.
The Dockerfile lists your whole application in one file so it’ll likely contain an already existing popular Docker image to begin with. Docker has a hub like GitHub where it hosts images that you can import to your project. For example, we could import the most up to date node image. We could then import dependencies specific to our app by pulling in our package.json from which we install all the node modules our app needs in the container. The final step is to run your app as you normally would locally. This is a Dockerfile in its most basic form:
# Import the latest node image from DockerHub
FROM node:latest# Create the app directory that will hold and run the container
# Copy package.json into the directory to install app dependencies
# A wildcard is used to copy both package.json & package-lock.json
COPY package*.json ./# Run a CLI command in the container to install dependencies
RUN npm install
# Copy everything else from our project directory into our container
COPY . .# Expose the port that the app runs on
EXPOSE 8080# Use the same command you would run locally to launch the app in # the container
CMD [ "node", "server.js" ]
Eventually, for ease of use with starting up and spinning down containers, you’ll want to make a docker-compose.yml file in your project directory. With a docker-compose.yml you’ll have access to more commands for more easily and automatically managing containers. The addition of this file is valuable for teams working on the same project who want identical images and a pleasant, straightforward experience when building and removing Docker containers.
Now that we packaged our app up in a perfect little shippable container how do we get it from our local system to the end-user?
Ship it to the Cloud 🚢
All the major cloud service providers, Amazon Web Services (AWS), Google Cloud Platform (GCP), and Microsoft Azure, offer ways of hosting your containerized app. With AWS we could ship our app to the end-user by launching our containerized app within Amazon Elastic Container Service (ECS). In our AWS account, we can start an ECS instance and mount our containerized app to that instance.
The general idea of cloud services is that you only pay for what you use. The ECS instance that holds your app lives inside a virtual machine on an Amazon server. And in that same server are other virtual machines that have their own isolated ECS instances belonging to other AWS customers. Instead of having to buy the whole server you just pay for the amount you use.
All Developers Should Understand Deployment
Regardless of your role within a developer team, you should understand at least the basics about how you containerize and ship your team’s apps. In 2019 even front-end developers are expected to have a role in creating Docker images/containers of their apps. And everyone on the team should know the basics of managing apps in the cloud because when something inevitably goes wrong with your app it’s very valuable that everyone is able to look at the cloud logs from AWS, GCP, or Azure and figure out what’s going on.
This short article was made to just introduce Docker and cloud services; if you’re interested in really learning these topics I would recommend these resources:
The official Docker documentation: https://docs.docker.com/get-started/
A Cloud Guru is a popular service for learning AWS: https://acloud.guru/
GCP’s containers page: https://cloud.google.com/containers/
Thank you for reading! Happy hacking!