New GCP database options to power your enterprise workloads

Databases power critical applications and workloads for enterprises across every industry, and we want to make it easier for businesses to use and manage those databases. Our goal is to provide you the capabilities to run any workload, existing and future, on Google Cloud. That’s why we offer secure, reliable and highly available database services, and have been working to deeply integrate open-source partner services running on Google Cloud Platform (GCP) to give you the freedom of choice when it comes to how to manage your data.Today, we’re announcing a number of enhancements to our database portfolio:Cloud SQL for Microsoft SQL Server in alpha Federated queries from BigQuery to Cloud SQLElastic Cloud on GCP now available in Japan and coming soon to Sydney Open the window to the cloud with Cloud SQL for Microsoft SQL Server When you move to the cloud, you shouldn’t have to reinvent the wheel. Our goal at GCP is to make it easy for everything you use on-premises to work as expected once you move to the cloud. Cloud SQL for Microsoft SQL Server (currently in alpha) lets you bring existing SQL Server workloads to GCP and run them in a fully managed database service. We’ve heard great feedback from our early access customers using Cloud SQL for SQL Server. For enterprises, this option means they can now experience fully managed SQL Server with built-in high availability and backup capability. You can lift and shift SQL Server workloads without changing apps, then use the data from these apps with other GCP services like BigQuery and AI tools to create more intelligent applications.Federated queries from BigQuery to Cloud SQLData can only create value for your business when you put it to work, and businesses need secure and easy-to-use methods to explore and manage data that is stored in multiple locations. To help, we’re continuing to expand federated queries to more GCP products so you can bring analysis to data, wherever it is and right within BigQuery. We currently support querying non-BigQuery native storage systems like Cloud Storage, Cloud Bigtable and Sheets, and today we’re extending the federated query capability to include Cloud SQL. This is just part of our continuing efforts to integrate our services across products to provide a seamless customer experience and build strong ecosystems around our products.   Elastic Cloud on GCP available in Japan; Sydney coming soonMigrating to the cloud can be challenging. That’s something we keep in mind as we develop our database products and integrate them with the rest of GCP. We do this with GCP-built services like Cloud SQL and Cloud Spanner, as well as through deeply integrated partner services running on GCP. These open source-centric strategic partners are in line with our belief that open source is a critical component of the public cloud. We’re pleased to announce the expanded availability of Elastic Cloud in Google Cloud’s Japan region, with Sydney region availability coming soon. As the creators of the Elastic Stack, built on Elasticsearch, Elastic builds self-managed and SaaS offerings that make data usable in real time and at scale for search use cases, like logging, security, and analytics. With more integration to come, you will soon be able to use your GCP commits toward Elastic Cloud, with a single bill from Google Cloud. How customers are using GCP databasesWe’ve heard from customers here in Japan that they’ve found new flexibility and scale with GCP databases, along with strong consistency and less operational overhead.   Merpay is a provider of secure online payment technology. Merpay’s Mercari platform has about 13 million monthly active users and depends on the performance and scalability of GCP database technology to run smoothly. “We adopted Cloud Spanner with little experience in order to store the data of a new smartphone payment service, to keep consistent with our culture of ‘Go Bold,’ where we encourage employees to take on challenges,”says Keisuke Sogawa, CTO of Merpay, Inc. “Additionally, adopting a microservices architecture based on Google Kubernetes Engine (GKE) made it possible for teams to freely and quickly develop services and maintain their service levels even as the organization grew larger. As a result, we released the Merpay service within a short span of 15 months, and today our provision of the service remains reliable for our customers.”Learn more about GCP databases, and get details about Forrester naming Google Cloud a Leader in The Forrester Wave Database-as-a-Service and The Forrester Wave Big Data NoSQL.Check out these Tokyo Cloud Next ’19 sessions for more about GCP databases:Announcing Federated Cloud SQLIntroduction to serverless application development using Cloud FirestoreRunning Redis on GCP: 4 つの構築シナリオCloud Spanner in Action
Quelle: Google Cloud Platform

Driving enterprise modernization with Google Cloud infrastructure

Organizations are adopting modern cloud architectures to deliver the best experience to their customers and benefit from greater agility and faster time to market. Google Cloud Platform (GCP) is at the center of this shift, from enabling customers to adopt hybrid and multi-cloud architectures to modernizing their services. Today, we’re announcing important additions to our migration and networking portfolios to help you with your modernization journey:Migration from Microsoft Azure to Google Compute Engine betaTraffic Director general availability Layer 7 Internal Load Balancer betaMigrate to GCP from more cloudsBusinesses migrate virtual machines from on-prem to Google Cloud all the time and, increasingly, they also want to move workloads between clouds. That’s why we’re announcing today that Migrate for Compute Engine is adding beta support for migrating virtual machines directly out of Microsoft Azure into Google Compute Engine (GCE). This complements Migrate for Compute Engine’s existing support for migrating VMs out of Amazon EC2. As a result, whether you’re migrating between clouds for better agility, to save money, or to increase security, you now have a way to lift and shift into Google Cloud—quickly, easily and cost-effectively.Trax, which uses GCP to digitize brick-and-mortar retail stores, has significantly accelerated its migration and freed up developer time thanks to the ease of use and flexibility of Migrate for Compute Engine. “Migrate for Compute Engine allowed our DevOps team to successfully move dozens of servers within a few hours and without utilizing developers or doing any manual setup,” said Mark Serdze, director of cloud infrastructure at Trax. “Previous migration sprints were taking as long as three weeks, so getting sprints down to as little as three hours with Migrate for Compute Engine was a huge time and energy saver for us. And being able to use the same solution to move VMs from on-prem, or from other cloud providers, will be very beneficial as we continue down our migration path.”Simplify transformation with enterprise-ready Service Mesh and modern load balancing As enterprises break monoliths apart and start modernizing services, they need solutions for consistent service and traffic management at scale. Organizations want to invest time and resources in building applications and innovating, not on the infrastructure and networking required to deploy and manage these services. Service mesh is rapidly growing in popularity because it solves these challenges by decoupling applications from application networking and service development from operations. To ease service mesh deployment and management, we’re announcing two enterprise-ready solutions that make it easier to adopt microservices and modern load balancing: general availability of Traffic Director and beta availability of Layer 7 Internal Load Balancer (L7 ILB).Traffic Director, now available in Anthos, is our fully managed, scalable, resilient service mesh control plane that provides configuration, policy and intelligence to Envoy or similar proxies in the data plane using open APIs, so customers are not locked in. Originally built at Lyft, Envoy is an open-source high-performance proxy that runs alongside the application to deliver common platform-agnostic networking capabilities, and together with Traffic Director, abstracts away application networking. Traffic Director delivers global resiliency, intelligent load balancing and advanced traffic control like traffic splitting, fault injection and mirroring to your services. You can bring your own Envoy builds or use certified Envoy builds from Tetrate.io.”Service mesh technologies are integral to the evolution from monolithic, closed architectures to cloud-native applications,” said Vishal Banthia, software engineer at Mercari, a leading online marketplace in Japan. “We are excited to see Traffic Director deliver fully-managed service mesh capabilities by leveraging Google’s strengths in global infrastructure and multi-cloud service management.”We’re also taking the capabilities of Traffic Director a step further for customers who want to modernize existing applications. With L7 ILB, currently in beta, you can now bring powerful load balancing features to legacy environments. Powered by Traffic Director and Envoy, L7 ILB allows you to deliver rich traffic control to legacy services with minimal toil—and with the familiar experience of using a traditional load balancer. Deploying L7 ILB is also a great first step toward migrating legacy apps to service mesh. “L7 ILB makes it simple for enterprises to deploy modern load balancing,” said Matt Klein, creator ofEnvoy Proxy. “Under the hood, L7 ILB is powered by Traffic Director and Envoy, so you get advanced traffic management simply by placing L7 ILB in front of your legacy apps.”Both L7 ILB and Traffic Director work out-of-the-box with virtual machines (Compute Engine) and containers (Google Kubernetes Engine or self-managed) so you can modernize services at your own pace.Deliver resilient connectivity for hybrid environments Networking is the foundation of hybrid cloud, and fast, reliable connectivity is critical, whether it’s with a high performance option like Cloud Interconnect or Cloud VPN for lower bandwidth needs. For mission-critical requirements, High Availability VPN and 100Gbps Dedicated Interconnect will soon be generally available, providing resilient connectivity with industry leading SLAs for deploying and managing multi-cloud services.We look forward to hearing how you use these new features. Please visit our website to learn more about our networking and migration solutions, including Migrate for Anthos.
Quelle: Google Cloud Platform

Understanding and leveraging Azure SQL Database’s SLA

When data is the lifeblood of your business, you want to ensure your databases are reliable, secure, and available when called upon to perform. Service level agreements (SLA) set an expectation for uptime and performance, and are a key input for designing systems to meet business needs. We recently published a new version of the SQL Database SLA, guaranteeing the highest availability among relational database services as well as introducing the industry’s first business continuity SLA. These updates further cement our commitment to ensuring your data is safe and the apps and processes your business relies upon continue running in the face of a disruptive event.

As we indicated in the recent service update, we made two major changes in the SLA. First, Azure SQL Database now offers a 99.995% availability SLA for zone redundant databases in its business critical tier. This is the highest SLA in the industry among all relational database services. It is also backed by up to a 100% monthly cost credit for when the SLA is not maintained. Second, we offer a business continuity SLA for databases in the business critical tier that are geo-replicated between two different Azure regions. That SLA comes with very strong guarantees of a five second recovery point objective (RPO) and a 30 second recovery time objective (RTO), including a 100% monthly cost credit when the SLA is not maintained. Azure SQL Database is the only relational database service in the industry offering a business continuity SLA.

The following table provides a quick side by side comparison of different cloud vendors’ SLAs.

Platform
Availability
Business continuity

Uptime
Max Credit
RTO
Max Credit
RPO
Max Credit

Azure SQL Database
99.995%
100%
30 seconds
100%
5 seconds
100%

AWS RDS
99.95%
100%
n/a
n/a
n/a
n/a

GCP Cloud SQL
99.95%
50%
n/a
n/a
n/a
n/a

Alibaba ApsaraDB
99.9%
25%
n/a
n/a
n/a
n/a

Oracle cloud
99.99%
25%
n/a
n/a
n/a
n/a

Data current as of July 18, 2019 and subject to change without notice.

Understanding availability SLA

The availability SLA reflects SQL Database’s ability to automatically handle disruptive events that periodically occur in every region. It relies on the in-region redundancy of the compute and storage resources, constant health monitoring and self-healing operations using automatic failover within the region. These operations rely on synchronously replicated data and incur zero data loss. Therefore, uptime is the most important metric for availability. Azure SQL Database will continue to offer a baseline 99.99% availability SLA across all of its service tiers, but is now providing a higher 99.995% SLA for the business critical or premium tiers in the regions that support availability zones. The business critical tier, as the name suggests, is designed for the most demanding applications, both in terms of performance and reliability. By integrating this service tier with Azure availability zones (AZ), we leverage the additional fault tolerance and isolation that AZs provide, which in turn allows us to offer a higher availability guarantee using the compute and storage redundancy across AZs and the same self-healing operations. Because the compute and storage redundancy is built in for business critical databases and elastic pools, using availability zones comes at no additional cost to you. Our documentation, “High-availability and Azure SQL Database” provides more details of how the business critical service tier leverages availability zones. You can also find the list of regions that support AZs in our documentation, “What are Availability Zones in Azure.”

99.99% availability means that for any database, including those in the business critical tier, the downtime should not exceed 52.56 minutes per year. Zone redundancy increases availability to 99.995%, which means a maximum downtime of only 26.28 minutes per year or a 50% reduction. A minute of downtime is defined as the period during which all attempts to establish a connection failed. To achieve this level of availability, all you need to do is select zone redundant configuration when creating a business critical database or elastic pool. You can do so programmatically using a create or update database API, or in Azure portal as illustrated in the following diagram.

We recommend using the Gen5 compute generation because the zone redundant capacity is based on Gen5 in most regions. The conversion to a zone redundant configuration is an asynchronous online process, similar to what happens when you change the service tier or compute size of the database. It does not require acquiescing or taking your application offline. As long as your connectivity logic is properly implemented, your application will not be interrupted during this transition.

Understanding business continuity SLA

Business continuity is the ability of a service to quickly recover and continue to function during catastrophic events with an impact that cannot be mitigated by the in-region self-healing operations. While these types of unplanned events are rare, their impact can be dramatic. Business continuity is implemented by provisioning stand-by replicas of your databases in two or more geographically separated locations. Because of the long distances between those locations, asynchronous data replication is used to avoid performance impact from network latency. The main trade-off of using asynchronous replication is the potential for data loss. The active geo-replication feature in SQL Database is designed to enable business continuity by creating and managing geographically redundant databases. It’s been in production for several years and we have plenty of telemetry to support very aggressive guarantees.

There are two common metrics used to measure the impact of business continuity events. Recovery time objective (RTO) measures how quickly the availability of the application can be restored. Recovery point objective (RPO) measures the maximum expected data loss after the availability is restored. Not only do we provide SLAs of five seconds for RPO and 30 seconds for RTO, but we also offer an industry first, 100% service credit if these SLAs are not met. That means if any of your database failover requests do not complete within 30 seconds or any time the replication lag exceeds five seconds in 99th percentile within an hour, you are eligible for a service credit for 100% of the monthly cost of the secondary database in question. To qualify for the service credit, the secondary database must have the same compute size as the primary. Note however, these metrics should not be interpreted as a guarantee of automatic recovery from a catastrophic outage. They reflect the Azure SQL’s reliability and performance when synchronizing your data and the speed of the failover when your application requests it. If you prefer a fully automated recovery process, you should consider auto-failover groups with automatic failover policy, which has a one hour RTO.

To measure the duration of the failover request, i.e. the RTO compliance, you can use the following query against the sys.dm_operation_status in master database on the secondary server. Please be aware that the operation status information is only kept for 24 hours.

SELECT datediff(s, start_time, last_modify_time) as [Failover time in seconds] FROM sys.dm_operation_status WHERE major_resource_id = '<my_secondary_db_name>', operation=’ALTER DATABASE FORCE FAILOVER ALLOW DATA LOSS ’, state=2 ORDER BY start_time DESC;

The following query against sys.dm_replication_link_status in the primary database will show replication lag in seconds, i.e. the RPO compliance, for the secondary database created on partner_server. You should run the same query every 30 seconds or less to have a statistically significant set of measurements per hour.

SELECT link_guid, partner_server, replication_lag_sec FROM sys.dm_replication_link_status

Combining availability and business continuity to build mission critical applications

What does the updated SLA mean to you in practical terms? Our goal is enabling you to build highly resilient and reliable services on Azure, backed by SQL Database. But for some mission critical applications, even 26 minutes of downtime per year may not be acceptable. Combining a zone redundant database configuration with a business continuity design creates an opportunity to further increase availability for the application. This SLA release is the first step toward realizing that opportunity.
Quelle: Azure

Run Windows Server and SQL Server workloads seamlessly across your hybrid environments

In recent weeks, we’ve been talking about the many reasons why Windows Server and SQL Server customers choose Azure. Security is a major concern when moving to the cloud, and Azure gives you the tools and resources you need to address those concerns. Innovation in data can open new doors as you move to the cloud, and Azure offers the easiest cloud transition, especially for customers running on SQL Server 2008 or 2008 R2 with concerns about end of support. Today we’re going to look at another critical decision point for customers as they move to the cloud. How easy is it to combine new cloud resources with what you already have on-premises? Many Windows Server and SQL Server customers choose Azure for its industry leading hybrid capabilities.

Microsoft is committed to enabling a hybrid approach to cloud adoption. Our commitment and passion stems from a deep understanding of our customers and their businesses over the past several decades. We understand that customers have business imperatives to keep certain workloads and data on premises, and our goal is to meet them where they are and prepare them for the future by providing the right technologies for every step along the way. That’s why we designed and built Azure to be hybrid from the beginning and have been delivering continuous innovation to help customers operate their hybrid environments seamlessly across on-premises, cloud and edge. Enterprise customers are choosing Azure for their Windows Server and SQL Server workloads. In fact, in a 2019 Microsoft survey of 500 enterprise customers, when those customers were asked about their migration plans for Windows Sever, they were 30 percent more likely to choose Azure.

Customers trust Azure to power their hybrid environments

Take Komatsu as an example. Komatsu achieved 49 percent cost reduction and nearly 30 percent performance gain by moving on-premises applications to Azure SQL Database Managed Instance and building a holistic data management and analytics solutions across their hybrid infrastructure.

Operating a $15 billion enterprise, Smithfield Foods slashed datacenter costs by 60 percent and accelerated application delivery from two months to one day using a hybrid cloud model built on Azure. Smithfield has factories and warehouses often in rural areas that have less than ideal internet bandwidth. It relies on Azure ExpressRoute to connect their major office locations globally to Azure to gain the flexibility and speed needed.

The government of Malta built a complete hybrid cloud eco-system powered by Azure and Azure Stack to modernize its infrastructure. This hybrid architecture, combined with a robust billing platform and integrated self-service backup, brings new level of flexibility and agility to the Maltese government operations, while also providing citizens and businesses more efficient services that they can access whenever they want.

Let’s look at some of Azure’s unique built-in hybrid capabilities.

Bringing the cloud to local datacenters with Azure Stack

Azure Stack, our unparalleled hybrid offering, lets customers build and run cloud-native applications with Azure services in their local datacenters or in disconnected locations. Today, it’s available in 92 countries and customers like Airbus Defense & Space, iMOKO, and KPMG Norway are using Azure Stack to bring cloud benefits on-premises.

We recently introduced Azure Stack HCI solutions so customers can run virtualized applications on-premises in a familiar way and enjoy easy access to off-the-shelf Azure management services such as backup and disaster recovery.

With Azure, Azure Stack, and Azure Stack HCI, Microsoft is the only cloud provider in the market that offers a comprehensive set of hybrid solutions.

Modernizing server management with Windows Admin Center

Windows Admin Center, a modern browser-based application free of charge, allows customers to manage Windows Servers on-premises, in Azure, or in other clouds. With Windows Admin Center, customers can easily access Azure management services to perform tasks such as disaster recovery, backup, patching, and monitoring. Since its launch just over a year ago, Windows Admin Center has seen tremendous momentum, managing more than 2.5 million server nodes each month.

Easily migrating on-premises SQL Server to Azure

Azure SQL Database is a fully managed and intelligent database service.  SQL Database is evergreen, so it’s always up to date: no more worry about patching, upgrades or End of Support. Azure SQL Database Managed Instance has the full surface area the of SQL Server database engine in Azure.  Customers use  Managed Instance to migrate SQL Server to Azure without changing the application code. Because the service is consistent with on-premises SQL Server, customers can continue using familiar features, tools and resources in Azure.

With SQL Database Managed Instance, customers like Komatsu, Carlsberg Group, and AllScripts were able to quickly migrate SQL databases to Azure with minimal downtime and benefit from built-in PaaS capabilities such as automatic patching, backup, and high availability.

Connecting hybrid environments with fast and secure networking services

Customers build extremely fast private connections between Azure and local infrastructure, allowing both to and through access using Azure ExpressRoute at bandwidths up to 100 Gbps. Azure Virtual WAN makes it possible to quickly add and connect thousands of branch sites by automating configuration and connectivity to Azure and for global transit across customer sites, using the Microsoft global network.

Customers are also taking full advantage of services like Azure Firewall, Azure DDoS Protection, and Azure Front Door Service to secure virtual networks and deliver the best application performance experience to users.

Managing anywhere access with a single identity platform

Over 90 percent of enterprise customers use Active Directory on-premises. With Azure, customers can easily connect on-premises Active Directory with Azure Active Directory to provide seamless directory services for all Office 365 and Azure services. Azure Active Directory gives users a single sign-on experience across cloud, mobile and on-premises applications, and secures data from unauthorized access without compromising productivity.

Innovating continuously at the edge

Customers are extending their hybrid environments to the edge so they can take on new business opportunities. Microsoft has been leading the innovation in this space. The following are some examples.

Azure Data Box Edge provides a cloud managed compute platform for containers at the edge, enabling customers to process data at the edge and accelerate machine learning workloads. Data Box Edge also enables customers to transfer data over the internet to Azure in real-time for deeper analytics, model re-training at cloud scale or long-term storage.

At Microsoft Build 2019, we announced Azure SQL Database Edge as available in preview, to bring SQL engine to the edge. Developers will now be able to adopt a consistent programming surface area to develop on a SQL database and run the same code on-premises, in the cloud, or at the edge.

Get started – Integrate your hybrid environments with Azure

Check out the resources on Azure hybrid such as overviews, videos, and demos so you can learn more about how to use Azure to run Windows Server and SQL Server workloads successfully across your hybrid environments.
Quelle: Azure

Top 4 Tactics To Keep Node.js Rockin’ in Docker

This is a guest post from Docker Captain Bret Fisher, a long time DevOps sysadmin and speaker who teaches container skills with his popular Docker Mastery courses including Docker Mastery for Node.js, weekly YouTube Live shows, and consults to companies adopting Docker.

Foxy, my Docker Mastery mascot is a fan of Node and Docker

We’ve all got our favorite languages and frameworks, and Node.js is tops for me. I’ve run Node.js in Docker since the early days for mission-critical apps. I’m on a mission to educate everyone on how to get the most out of this framework and its tools like npm, Yarn, and nodemon with Docker.

There’s a ton of info out there on using Node.js with Docker, but so much of it is years out of date, and I’m here to help you optimize your setups for Node.js 10+ and Docker 18.09+. If you’d rather watch my DockerCon 2019 talk that covers these topics and more, check it out on YouTube.

Let’s go through 4 steps for making your Node.js containers sing! I’ll include some quick “Too Long; Didn’t Read” for those that need it.

Stick With Your Current Base Distro

TL;DR: If you’re migrating Node.js apps into containers, use the base image of the host OS you have in production today. After that, my favorite base image is the official node:slim editions rather than node:alpine, which is still good but usually more work to implement and comes with limitations.

One of the first questions anyone asks when putting a Node.js app in Docker, is “Which base image should I start my Node.js Dockerfile from?”

slim and alpine are quite smaller than the default image

There are multiple factors that weigh into this, but don’t make “image size” a top priority unless you’re dealing with IoT or embedded devices where every MB counts. In recent years the slim image has shrunk down in size to 150MB and works the best across the widest set of scenarios. Alpine is a very minimal container distribution, with the smallest node image at only 75MB. However, the level of effort to swap package managers (apt to apk), deal with edge cases, and work around security scanning limitations causes me hold off on recommending node:alpine for most use cases.

When adopting container tech, like anything, you want to do what you can to reduce the change rate. So many new tools and processes come along with containers. Choosing the base image your devs and ops are most used to has many unexpected benefits, so try to stick with it when it makes sense, even if this means making a custom image for CentOS, Ubuntu, etc.

Dealing With Node Modules

TL;DR: You don’t have to relocate node_modules in your containers as long as you follow a few rules for proper local development. A second option is to move mode_modules up a directory in your Dockerfile, configure your container properly, and it’ll provide the most flexible option, but may not work with every npm framework.

We’re all now used to a world where we don’t write all the code we run in an app, and that means dealing with app framework dependencies. One common question is how to deal with those code dependencies in containers when they are a subdirectory of our app. Local bind-mounts for development can affect your app differently if those dependencies were designed to run on your host OS and not the container OS.

The core of this issue for Node.js is that node_modules can contain binaries compiled for your host OS, and if it’s different then the container OS, you’ll get errors trying to run your app when you’re bind-mounting it from the host for development. Note that if you’re a pure Linux developer and you develop on Linux x64 for Linux x64, this bind-mount issue isn’t usually a concern.

For Node.js I offer you two approaches, which come with their own benefits and limitations:

Solution A: Keep It Simple

Don’t move node_modules. It will still sit in the default subdirectory of your app in the container, but this means that you have to prevent the node_modules created on your host from being used in the container during development.

This is my preferred method when doing pure-Docker development. It works great with a few rules you must follow for local development:

Develop only through the container. Why? Basically, you don’t want to mix up the node_modules on your host with the node_modules in the container. On macOS and Windows, Docker Desktop bind-mounts your code across the OS barrier, and this can cause problems with binaries you’ve installed with npm for the host OS, that can’t be run in the container OS.Run all your npm commands through docker-compose. This means your initial npm install for your project should now be docker-compose run <service name> npm install.

Solution B: Move Container Modules and Hide Host Modules

Relocate node_modules up the file path in the Dockerfile so you can develop Node.js in and out of the container, and the dependencies won’t clash which you switch between host-native development and Docker-based development.

Since Node.js is designed to run on multiple OS’s and architectures, you may not want to always develop in containers. If you want the flexibility to sometimes develop/run your Node.js app directly on the host, and then other times spin it up in a local container, then Solution B is your jam.

In this case you need a node_modules on host that is built for that OS, and a different node_modules in the container for Linux.

The basic lines you’ll need to move node_modules up the path

Rules for this solution include:

Move the node_modules up a directory in the container image. Node.js always looks for a node_modules as a subdirectory, but if it’s missing, it’ll walk up the directory path until it finds one. Example of doing that in a Dockerfile here. To prevent the host node_modules subdirectory from showing up in the container, use a workaround I call an “empty bind-mount” to prevent the host node_modules from ever being used in the container. In your compose YAML it would look like this.This works with most Node.js code, but some larger frameworks and projects seem to hard-code in the assumption that node_modules is a subdirectory, which will rule out this solution for you.

For both of these solutions, always remember to add node_modules to your .dockerignore file (same syntax as .gitignore) so you’ll never accidentally build your images with modules from the host. You always want your builds to run an npm install inside the image build.

Use The Node User, Go Least Privilege

All the official Node.js images have a Linux user added in the upstream image called node. This user is not used by default, which means your Node.js app will run as root in the container by default. This isn’t the worst thing, as it’s still isolated to that container, but you should enable in all your projects where you don’t need Node to run as root. Just add a new line in your Dockerfile: USER node

Here are some rules for using it:

Location in the Dockerfile matters. Add USER after apt/yum/apk commands, and usually before npm install commands.It doesn’t affect all commands, like COPY, which has its own syntax for controlling owner of files you copy in.You can always switch back to USER root if you need to. In more complex Dockerfiles this will be necessary, like my multi-stage example that includes running tests and security scans during optional stages.Permissions may get tricky during development because now you’ll be doing things in the container as a non-root user by default. The way to often get around this is to do things like npm install by telling Docker you want to run those one-off commands as root: docker-compose run -u root npm install

Don’t Use Process Managers In Production

TL;DR: Except for local development, don’t wrap your node startup commands with anything. Don’t use npm, nodemon, etc. Have your Dockerfile CMD be something like  [“node”, “file-to-start.js”] and you’ll have an easier time managing and replacing your containers.

Nodemon and other “file watchers” are necessary in development, but one big win for adopting Docker in your Node.js apps is that Docker takes over the job of what we used to use pm2, nodemon, forever, and systemd for on servers.

Docker, Swarm, and Kubernetes will do the job of running healthchecks and restarting or recreating your container if it fails. It’s also now the job of orchestrators to scale the number of replicas of our apps, which we used to use tools like pm2 and forever for. Remember, Node.js is still single-threaded in most cases, so even on a single server you’ll likely want to spin up multiple container replicas to take advantage of multiple CPU’s.

My example repo shows you how to using node directly in your Dockerfile, and then for local development, either build use a different image stage with docker build –target <stage name>, or override the CMD in your compose YAML.

Start Node Directly in Dockerfiles

TL;DR I also don’t recommend using npm to start your apps in your Dockerfile. Let me explain.

I recommend calling the node binary directly, largely due to the “PID 1 Problem” where you’ll find some confusion and misinformation online about how to deal with this in Node.js apps. To clear up confusion in the blogosphere, you don’t always need a “init” tool to sit between Docker and Node.js, and you should probably spend more time thinking about how your app stops gracefully.

Node.js accepts and forwards signals like SIGINT and SIGTERM from the OS, which is important for proper shutdown of your app. Node.js leaves it up to your app to decide how to handle those signals, which means if you don’t write code or use a module to handle them, your app won’t shut down gracefully. It’ll ignore those signals and then be killed by Docker or Kubernetes after a timeout period (Docker defaults to 10 seconds, Kubernetes to 30 seconds.) You’ll care a lot more about this once you have a production HTTP app that you have to ensure doesn’t just drop connections when you want to update your apps.

Using other apps to start Node.js for you, like npm for example, often break this signaling. npm won’t pass those signals to your app, so it’s best to leave it out of your Dockerfiles ENTRYPOINT and CMD. This also has the benefit of having one less binary running in the container. Another bonus is it allows you to see in the Dockerfile exactly what your app will do when your container is launched, rather then also having to check the package.json for the true startup command.

For those that know about init options like docker run –init or using tini in your Dockerfile, they are good backup options when you can’t change your app code, but it’s a much better solution to write code to handle proper signal handling for graceful shutdowns. Two examples are some boilerplate code I have here, and looking at modules like stoppable.

Is That All?

Nope. These are concerns that nearly every Node.js team deals with, and there’s lots of other considerations that go along with that. Topics like multi-stage builds, HTTP proxies, npm install performance, healthchecks, CVE scanning, container logging, testing during image builds, and microservice docker-compose setups are all common questions for my Node.js clients and students.

If you’re wanting more info on these topics, you can watch my DockerCon 2019 session video on this topic, or check my 8-hours of Docker for Node.js videos at https://www.bretfisher.com/node Thanks for reading. You can reach me on Twitter, get my weekly DevOps and Docker newsletter, subscribe to my weekly YouTube videos and Live Show, and check out my other Docker resources and courses.

Keep on Dockering!

Docker Captain @bretfisher dives into 4 Ways to Keep #nodejs Rockin in DockerClick To Tweet

The post Top 4 Tactics To Keep Node.js Rockin’ in Docker appeared first on Docker Blog.
Quelle: https://blog.docker.com/feed/