This is my first post on dev.to, comments and feedbacks are appreciated! 😄
Not some time before, I have problems with my debit card which made me can’t pay all my digital bills, including my DigitalOcean droplets which hosts my landing page and other Docker services. But my landing page must not go down. So here’s how I deployed my landing page to ZEIT ▲now for free!
- Packing the Node.js app
- Deploying to ZEIT ▲now
- Configuring the Deployment Domain
My landing page is powered with Next.js, which is also from ZEIT. If I’m hosting things manually like in the old times, I need to access my server, copy my project, install Node.js, add a service to run
NODE_ENV=production node server.js, and so on. But with the power of Docker, I just need to make a
Dockerfile in order to “pack” things up. Here’s the configuration file from the repository:
FROM node:alpine WORKDIR /srv/app COPY . . RUN yarn install EXPOSE 6796 ENV NODE_ENV=production RUN yarn build CMD [ "node", "server.js" ]
Here you can see that the
Dockerfile is using an official prebuilt image (
node:alpine), installs the node modules, exposes the 6796 port, and builds the webpage. No need to configure things bare metally (is that even a word). When pushing the project to GitHub, the Docker Hub repository automatically detects the
Dockerfile and builds the project, ready to be pulled later.
▲now is a command-line app which also has a GUI application that bridges the CLI one. You can install via
yarn, or download the GUI releases on their GitHub page.
# using npm npm -g i now # using yarn yarn global add now
After installing the app, proceed to logging in my credentials by typing
now login and enter according to the prompt. After logging in, with just a few commands, I can have my landing page hosted on ▲now in no time. There are two ways to deploy a Docker app:
This method means that when deploying the project, ▲now will build the image independently on their servers (not pulling from Docker Hub) then run the built image. On the project directory, I ran this command:
now --docker --public --name landing
This command will deploy the project as a public Docker project with the alias
landing, which will be hosted on a generated URL.
If you have built your project image on Docker Hub or elsewhere on a public registry, you can create a directory with a single Dockerfile containing your Docker image repository, and run the same command as before:
After deploying the project, you’ll notice the random strings in the middle of the URL (e.g. landing-hnkfxdhefc.now.sh). Every deployed project will have a generated strings, which you can change the URL by using the command
# adds an alias to griko.id now alias set landing-hnkfxdhefc.now.sh griko.id # adds an alias to griko.now.sh now alias set landing-hnkfxdhefc.now.sh griko
When submitting the
now alias command with an external domain (not bought from ZEIT domains), the console will return an error with the required TXT record to be set on your DNS service. To use an external domain, you need to configure your DNS records with two ZEIT DNS records: a generated TXT record, and a
CNAME/ALIAS record of
In short, make your
now --docker for deploying your Docker project on ZEIT ▲now, set custom domain using now domains.
Many thanks to the ZEIT team for the awesome infrastructure and the assistance on deploying and configuring my project, especially Guillermo Rauch and Timothy for the insights! Also credits to Docker Hub and Cloudflare for the DNS management.