DEV Community

Cover image for Nx + NextJS + Docker: Containerizing our application

Nx + NextJS + Docker: Containerizing our application

Sebastián Duque G on June 28, 2023

Introduction In the previous blog post, we learned how to create a Next.js application using Nx and set up our development environment. ...
Collapse
 
thebrogramm3r profile image
MichaelAngelo Rivera

you are AWESOME!!!!!!!!!!!!!!!!!!!!

Collapse
 
sebastiandg7 profile image
Sebastián Duque G

I'm glad it was helpful! 😀

Collapse
 
beldenschroeder profile image
Belden Schroeder

I got this to work by building my image on my Docker Desktop and deploying it to Docker Hub. Now, I want to do this using Skaffold. How would any of this code need to change for that?

Since Skaffold gives a random name for every container I build, would this not work, given that you have to specify the container name beforehand in the Nx project.json file in containers > configuration > production?

If so, how do you get around this?

Collapse
 
fkrautwald profile image
Frederik Krautwald

Try to build the Dockerfile using just docker and it fails.

Collapse
 
sebastiandg7 profile image
Sebastián Duque G

Hey. Can you share what command did you use?

Collapse
 
fkrautwald profile image
Frederik Krautwald

docker build

It works when using the nx-container command, but docker files should stand on their own.

Thread Thread
 
sebastiandg7 profile image
Sebastián Duque G • Edited

Aboslutely! The equivalent build command to the container target would be:

From the workspace root:
docker buildx build --file apps/my-app/Dockerfile --tag my-app:latest dist/apps/my-app

You first need to build the app as Nx does prior to building the docker image.

Collapse
 
naviat profile image
naviat

really good!!
I have a question: how to config in project.json when I have one app but want to build multi docker image from this app with different environment?

Collapse
 
sebastiandg7 profile image
Sebastián Duque G

You could add different configurations to the container target with different Dockerfiles, tags, etc.

Collapse
 
xwlee profile image
Lee Xiang Wei

Great article. Keep more coming.

Collapse
 
kaualandi profile image
kaualandi

I'm need help to configure Docker Dev Containers for programming with Nx Angular