Docker-compose Nuxtjs

690 Views Asked by At

I am creating my first Nuxtjs app but I want to use Docker-compose. I was able to Dockerize my application following this tutorial: https://dockerize.io/guides/docker-nuxtjs-guide

Now I want to bring it to the next level using compose but I'm not too familiar with Serverside-rendering and how this could affect my docker-compose file. Unfortunately I cannot find any guide on how to use docker-compose on NuxtJS apps. Do you know where I can find a good guide for it? Thanks.

UPDATE: I created a docker-compose.yml file and is working but still I can't find any guide to see if it is a good yml file (best practices etc.)

version: '3'

services:
  web:
    build: .
    command: npm run dev
    ports:
      - '3000:3000'
1

There are 1 best solutions below

4
On BEST ANSWER

If you can already run your app in Docker, you won't gain much from Docker Compose, unless you need to run multiple containers. As stated in Overview of Docker Compose, Compose is a tool for defining and running multi-container Docker applications.

Based on the linked tutorial, docker-compose.yaml could look something like this:

version: "3"

services:
  nuxt:
    image: nuxtjs-tutorial:latest
    ports:
      - "3000:3000"
    environment:
      - NUXT_HOST="0.0.0.0"
      - NUXT_PORT="3000"

The environment variables do not need to be set from the Compose file, this is just an example. Compose allows you to set many options, as described in the Compose file reference. For example, you could run the app in Compose using entrypoint instead of CMD in Dockerfile. Or you could only copy package.json in Dockerfile, build the dependencies during image build, and mount your code using volumes.

I found multiple example references online, but I wouln't consider any of them best practice. Best to read the official Documentation.

Regarding your update, based on the Dockerfile in the tutorial, you do not even need the build and command entries, only image and ports. But as I said above, you can set many options from Compose, best described in official documentation.